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 

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.


- Ken

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to