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 > Query Help needed

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-24-04, 20:00
cmptrguru7 cmptrguru7 is offline
Registered User
 
Join Date: Feb 2002
Posts: 43
Query Help needed

I have two tables

Table1
ID
Name

table2
Id
code

I need a query that will give me the ID's in table 2 that are not in table 1. Yes I know this should be handled by key constraints, but it is not so I need to find the keys in table 2 that do not have a match in table 1. If I do a join I only get the records where the id's are equal.
Reply With Quote
  #2 (permalink)  
Old 02-24-04, 22:15
chuzhoi chuzhoi is offline
Registered User
 
Join Date: Dec 2002
Posts: 134
Re: Query Help needed

1. select id from table2 where id not in (select id from table1 )
2. select id from table2 where not exists (select * from table1 where table1.id = table2.id)
3. select id from table2 except select id from table1
4. select distinct table2.id from table2 left outer join table1 on table1.id = table2.id where table1.id is null
Reply With Quote
  #3 (permalink)  
Old 02-25-04, 11:11
cmptrguru7 cmptrguru7 is offline
Registered User
 
Join Date: Feb 2002
Posts: 43
Thank you number 4 was the correct answer for my problem. My software will not allow subqueries so that one worked just fine. Thanks again.
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