[ale] Embarassingly Rusty with SQL

Greg Sabino Mullane greg at turnstep.com
Mon Mar 24 20:45:55 EDT 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160


> 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?

SELECT lastname, firstname
FROM table1 t
WHERE NOT EXISTS
  (SELECT 1 FROM table2 WHERE t.lastname=lastname AND t.firstname=firstname);

Not quite as good:

SELECT lastname, firstname
FROM table1
EXCEPT
SELECT lastname, firstname
FROM table2;

- --
Greg Sabino Mullane greg at turnstep.com
PGP Key: 0x14964AC8 200803242043
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----

iEYEAREDAAYFAkfoSxMACgkQvJuQZxSWSsgFCwCgjkEp/FsjYM/tVOyfXveVYxi3
3F8AoPsi39erfTJM85ll92gFLoR2mIfj
=FytO
-----END PGP SIGNATURE-----




More information about the Ale mailing list