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 > Data Access, Manipulation & Batch Languages > ANSI SQL > select query for records which do not appear in another linked table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-06-02, 16:51
Jon GS Jon GS is offline
Registered User
 
Join Date: Feb 2002
Posts: 3
Question select query for records which do not appear in another linked table

I have a successful inner join query to select records from one table which have a corresponding record in another table with the same unique id. "select table1.name, table1.ID, table2.address from table1 inner join table2 on table1.ID=table2.ID"

How can I select records from table1 whose ID does NOT appear in table2?

Any help much appreciated.

JGS
Reply With Quote
  #2 (permalink)  
Old 02-06-02, 19:19
alligatorsql.com alligatorsql.com is offline
Registered User
 
Join Date: Jul 2001
Location: Germany
Posts: 189
Hello,

which database do you use ?

This would help

Greetings

Manfred Peter
(Alligator Company)
http://www.alligatorsql.com
Reply With Quote
  #3 (permalink)  
Old 02-07-02, 13:20
Jon GS Jon GS is offline
Registered User
 
Join Date: Feb 2002
Posts: 3
database type

used to postgesql but client now insists on MS SQL Server - alas alack!
thanks Jgs
Reply With Quote
  #4 (permalink)  
Old 02-08-02, 21:05
rwilkerson rwilkerson is offline
Registered User
 
Join Date: Feb 2002
Location: Baltimore, MD
Posts: 26
Lightbulb Two Possibilities

First using an outer join

SELECT table1.name,
table1.ID,
table2.address
FROM table1 LEFT JOIN table2
ON table1.ID=table2.ID
WHERE table2.address IS NULL

Second using a subquery

SELECT table1.name,
table1.ID
FROM table1
WHERE NOT EXISTS ( SELECT 1
FROM table2
WHERE table1.id = table2.id )

Hope this helps.
__________________
Rob Wilkerson
Reply With Quote
  #5 (permalink)  
Old 02-11-02, 03:52
Jon GS Jon GS is offline
Registered User
 
Join Date: Feb 2002
Posts: 3
Many thanks

Really apprecate the help, used the subquery method.

Many thanks

Jon
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