Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Posts
    4

    Unanswered: 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

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    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)

  3. #3
    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

  4. #4
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    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);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •