You want to use a LEFT JOIN, which will select all the records from A and link them with records in B if there are any. If there are no matches in B, the the fields from B will be NULL. You then just check for the NULL value (no match) in a B field and use that as your filter.

SELECT A.*,B.D FROM A LEFT JOIN B ON A.C=B.D WHERE B.D IS NULL


----- Original Message ----- From: "Aaron Cannon" <[EMAIL PROTECTED]>
To: <mysql@lists.mysql.com>
Sent: Wednesday, January 03, 2007 3:47 PM
Subject: select statement question


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi all.  I hope this is the right place to ask this.

I have two tables, A and B.  Each of these tables has a column with
integers.  The column in table A is C and the one in B is D.

I need a select statement that will return all records whose C value is not
in any row in D.

for example:
C =
1
2
3
4
5
6
7
8
11

D =
2
4
6
8
10

and the statement would return:
1
3
5
7
11

Probably an easy question for those of you more experienced but I have no
clew.

Thanks in advance.

Sincerely
Aaron Cannon


- --
Skype: cannona
MSN/Windows Messenger: [EMAIL PROTECTED] (don't send email to the hotmail
address.)

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32) - GPGrelay v0.959
Comment: Key available from all major key servers.

iD8DBQFFnBbLI7J99hVZuJcRAiF3AJ4mR4UjLa0sG+hIDbErj7LvuzfU4wCggEDh
DtnfmVsHL84me4qVw/mA4s8=
=l2gE
-----END PGP SIGNATURE-----


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to