If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Query Help - Join statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-19-09, 06:14
madonnagrace madonnagrace is offline
Registered User
 
Join Date: Aug 2009
Posts: 4
Question Query Help - Join statement

hi ,

Pls help with a query where certain fields FROM table 1 is to be selected WHICH are not present in table 2.

Hav tried the general query of "SELECT table1.item_id FROM table1 where table1.item_id NOT IN (SELECT item_id FROM table 2)" but it does not work in the mysql DB whereas the same query worked well with INgRES ...

Pls help if it could work with a JOIN statement and how ...

Thanks
regards
madonna
Reply With Quote
  #2 (permalink)  
Old 08-19-09, 06:55
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by madonnagrace
but it does not work in the mysql DB
oh yes it does

well, it does assuming you are on a recent version, and by recent i mean one that was released in the current millenium

anyone still running 3.23 or 4.0 deserves these types of difficulties

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 08-19-09, 07:18
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
The key is an OUTER join
Code:
SELECT table1.item_id
FROM   table1
 LEFT
  JOIN table2
    ON table2.item_id = table1.item_id
WHERE  table2.item_id IS NULL
__________________
George
Twitter | Blog
Reply With Quote
  #4 (permalink)  
Old 08-19-09, 08:12
madonnagrace madonnagrace is offline
Registered User
 
Join Date: Aug 2009
Posts: 4
thanks gvee georgee ... and r937 will have a look at your SQl book for future ref if any ...
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On