mysql> SELECT name FROM animal WHERE id NOT IN (SELECT animal_id FROM
animal_food);

Or

mysql> SELECT name FROM animal 
  WHERE NOT EXISTS (SELECT animal_id FROM animal_food WHERE
animal.id=animal_id);


>From http://www.databasejournal.com/features/mysql/article.php/3434641

Pat Newberry
www.gypsyfarm.com










-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Ski Dawg
Sent: Saturday, November 26, 2005 1:34 PM
To: [email protected]
Subject: [php_mysql] Selecting values not in a secondary table


Hello all,

I am trying to select all values from table1 where table1.id is NOT in
table2.

To better explain, table1 has several different records with the primary
key on the field id (table1.id). table2 also has several other records,
using table1.id field as a secondary key (table2.secid). I would like to
get all the records from table1 where the value of id field (table1.id)
is not in table2 (table2.secid).

Does anyone know how to do this or can point me to a website that will
explain how I should do this?
--
Doug

Registered Linux User #285548 (http://counter.li.org)
----------------------------------------
Random Thought:
Dorothy:   But how can you talk without a brain?
Scarecrow: Well, I don't know... but some people without brains do an
           awful lot of talking.
             -- The Wizard of Oz




The php_mysql group is dedicated to learn more about the PHP/MySQL web
database possibilities through group learning.  
Yahoo! Groups Links



 




------------------------ Yahoo! Groups Sponsor --------------------~--> 
Get fast access to your favorite Yahoo! Groups. Make Yahoo! your home page
http://us.click.yahoo.com/dpRU5A/wUILAA/yQLSAA/CefplB/TM
--------------------------------------------------------------------~-> 

The php_mysql group is dedicated to learn more about the PHP/MySQL web database 
possibilities through group learning.  
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php_mysql/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to