Re: select statement question
- Date: Fri, 5 Jan 2007 10:00:06 -0500
- From: "Brent Baisley" <brenttech@xxxxxxxxx>
- Subject: Re: select statement question
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" <cannona@xxxxxxxxxxxxxxxxxxxxxx>
To: <mysql@xxxxxxxxxxxxxxx> 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: cannona@xxxxxxxxxxx (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/mysql?unsub=brenttech@xxxxxxxxx
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=royale@xxxxxxxxxx
- References:
- select statement question
- From: Aaron Cannon
- select statement question
- Prev by Date: Re: Data types and space needs
- Next by Date: mysqld_safe failing
- Previous by thread: Re: select statement question
- Next by thread: Experience with upgrade to Linux 4GB RAM from Windows 2003: what kernel which release to prefer?
- Index(es):