Tricky database query involving two tables

From: Date: Thu, 01 Mar 2001 02:50:19 +0000
Subject: Tricky database query involving two tables
Groups: php.db 
Request: Send a blank email to php-db+get-7032@lists.php.net to get a copy of this message
I have a tricky database query I can't figure out how to write. I have a PHP app using MySQL that does a query like this: (main query) select * from A left join B on something where B.thing = "1" This gets me everything in A where its corresponding element in B has a certain attribute. What I want is to be able to now do this: select * from A where A not in the result set of the main query I can't just do: select * from A left join B on something where B.thing != "1" or B.thing is NULL because things in A might occur more than once in B, (or not at all in B, but that's covered by the NULL part), and so this query would return things in A that I already got in the main query. Is there a way to do this in MySQL? Or do I have to just query everything, and then have the skipping logic be in PHP? I'd love to encapsulate this in a query. Would it involve subqueries (something I know that MySQL doesn't directly support)? Let me know if I need to be more clear or specific in my question. Thanks! - Ken kenzo@free-music.com

« previous php.db (#7032) next »