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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with mysql select please

Status
Not open for further replies.

georgeocrawford

Technical User
Aug 12, 2002
111
GB
Hi,

If I have two tables, which both have a column named 'forum_id', how can I find a list of all the forum_id's which appear in table 1 but not in table 2?

eg:

table 1

forum_id forum_name
1 test
2 forum
3 george
4 hello


table 2

forum_id post_id
1 7
4 16



I want to get results of '2' and '3' from this operation.

______________________

George
 
hmm, you will need to use a join command to do this and reference the 2 fields you wish to compare.
look here look here for more info. hope this helps.
 
Got it - thanks a lot!

SELECT a.forum_id FROM table1 a LEFT JOIN table2 b USING (forum_id) WHERE b.forum_name is NULL

it works - does it look correct?

______________________

George
 
if it works then it looks correct. sorry, just know about this command, never used it.
 
thanks for the quick responses - I'm working in PHP and I've replaced 25 lines of stupid array loops with one MySQL query - NICE!

______________________

George
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top