Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Problems, PLEASE HELP!

Status
Not open for further replies.

sshelby1

Programmer
Jan 9, 2005
4
US
I am trying to select all the records in a table that DO NOT have a matching record in a second table. I hope this makes sense. Here is my query:

SELECT * FROM table1 WHERE table1.ID NOT IN(SELECT ID FROM table2);

Does anyone see what I might be doing wrong or have a better way of doing this?

Thanks!
sshelby1
 
You're probably getting an error at "SELECT ID". You're probably getting this because your version of MySQL does not support subqueries.

A way around this is a join. Something like this should work:

Code:
select table1.*
  from table1 left join table2
    on table1.id = table2.id
 where table2.id is null;

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top