Jump to content

Archived

This topic is now archived and is closed to further replies.

brown2005

slect a record that is in table 1 but not in table 2

Recommended Posts

hi,

say i have

table 1--------------

members_id
members_name

and then table 2

selected_id

wat i want to do is select all the records in table 1 that do not have their id in table 2?

Share this post


Link to post
Share on other sites
my sql is rusty but try this, don't yell if it doesn't work:

$sql = "select * from table1 where members_id not in (select selected_id from table2 where 1)";

Share this post


Link to post
Share on other sites
I think hvle's is a little better then mine, i would do

"SELECT table_1.id FROM table_1.id WHERE (SELECT id FROM table_2.id WHERE table_2.id NOT LIKE table1.id)";


but again, don't yell at me if it doesn't work.

Share this post


Link to post
Share on other sites
Another Option, I think:
"SELECT table_1.id,table_1.id as t1id  FROM table_1 WHERE (SELECT COUNT(*) FROM table_2 WHERE table_2.id=t1id) < 1"

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.