[ale] Embartassingly Rusty with SQL
Ed Landa
elanda at xilogix.net
Mon Mar 24 23:46:38 EDT 2008
> Given two tables (Table 1, Table 2), each with the fields lastname,
> firstname, how do I do a listing of the tuples in Table 1 that do not
> contain the same lastname and firtname in Table 2?
Depending on the database engine you're using, the size of the tables,
appropriateness of indexes and the phase of the moon, you may get better
optimization out of a JOIN than a sub-select.
SELECT one.lastname,one.firstname
FROM one
LEFT OUTER JOIN two ON
(one.lastname=two.lastname AND one.firstname=two.firstname)
HAVING two.lastname IS NULL;
YMMV. Use any explain/query-plan optimization tools you have if
performance is important.
Ed
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.ale.org/pipermail/ale/attachments/20080324/f0599659/attachment.bin
More information about the Ale
mailing list