query that finds when something is NOT IN a table

From: Date: Thu, 06 Mar 2003 21:59:22 +0000
Subject: query that finds when something is NOT IN a table
Groups: php.db 
Request: Send a blank email to php-db+get-26142@lists.php.net to get a copy of this message
(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

« previous php.db (#26142) next »