query that finds when something is NOT IN a table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



(Using MySQL and PHP)

I need to only return a row from table1 if its id is not found in table2.
The query below is how I think it should work. However (as I had imagined),
this doesn't work. Syntax error (you can't put a select inside a select like
that).

SELECT table1.id FROM table1 WHERE table1.sold=1 AND table1.id NOT IN
(SELECT table2.table1_id FROM table2)

(and no, those aren't the real table or field names - just trying to be
clear)

I could do a SELECT first that gets all the values in the table2, then (in
PHP) run through a result set of rows from table1, checking each time to see
if its id is in table2, and if it isn't, display it...but this seems
excessive.

I went through all of the functions to use in a WHERE clause in my MySQL
book...am I missing something?

Thanks,
--
Katie Evans-Young
Web Developer
Evans-Young Designs
E-mail: katie682@comcast.net
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.445 / Virus Database: 250 - Release Date: 1/21/2003


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux