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 > Difference between two sets

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-14-04, 18:47
Cshamoh Cshamoh is offline
Registered User
 
Join Date: Jan 2004
Posts: 4
Difference between two sets

Hi everyone,
This is my first post... I had to do it.
Lets say I got two tables:
1) Autors
2) Books
you can keep autors' data even if they haven't written any book. My question is how do I find them?
I already got subset of autors that have written one and a set of all existing autors. Now I need to get difference between those two sets right? Can ya help me?
Thnx v. much
Reply With Quote
  #2 (permalink)  
Old 01-15-04, 06:04
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: Difference between two sets

select author_id from authors
minus
select author_id from books

... assuming your DBMS supports MINUS (or possibly EXCEPT, which is the same thing)
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #3 (permalink)  
Old 01-15-04, 06:18
Cshamoh Cshamoh is offline
Registered User
 
Join Date: Jan 2004
Posts: 4
Rite,
I forgot to mention the most important thing - its MS SQL SRV and from what I know it doesnt support MINUS or EXCEPT
Reply With Quote
  #4 (permalink)  
Old 01-15-04, 06:20
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
In that case you could use NOT EXISTS...

select * from authors where not exists (select 1 from books where books.author_id = authors.author_id);
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
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