Hot answers tagged

2

You may need to alter this slightly for postgres (is is MS SQL syntax) but something like: SELECT id FROM contacts LEFT OUTER JOIN FROM case_contacts ON case_contacts.contact_id = contacts.id LEFT OUTER JOIN FROM case_payments ON case_payments.contact_id = contacts.id LEFT OUTER JOIN FROM invoices ON invoices.contact_id = contacts.id WHERE ...


2

There is a third approach which has some of the advantages of your two options - put an actual code in the code table. By this I mean a short character sequence that captures the essence of the full value and is unique. For your given example it may be Idn: 1 Name: Democrats Code: D (or DEM) The Code is carried into transactional tables as a foreign ...


1

For the simple result (just the id), EXCEPT might be simplest and fastest: Also, since you write: I get their primary keys in an array Simply use unnest() and don't waste time joining to the contacts table: SELECT id FROM unnest('{1,10,20,1557,5000,15057}'::int[]) id -- actual array (not list) EXCEPT ALL SELECT contact_id FROM case_contacts EXCEPT ...


1

By IDN, I take it you mean an IDENTITY, SEQUENCE or AUTO_INCREMENT field? You should take a look here and here. Note, section 5 (Misusing Data values as Data Elements) of the first reference, underneath figure 10 Of course you can have a separate table for the sales persons and then reference it using a foreign key, preferably with a simple surrogate ...



Only top voted, non community-wiki answers of a minimum length are eligible