Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2008
    Posts
    24

    Unanswered: Query involving multiple tables ...

    Hello,

    I have two tables:

    TableA
    ------------
    aKey char(10)
    ...

    TableB
    -------------
    aKey char(10)
    ...

    I need to select all values of "aKey" in TableB that do not exist in TableA.

    Now, say I have tables TableB-TableZ, and for each I need to execute that same query (with TableA) and consolidate the results.

    Thanks for any suggestions / best practice tips,

    chasse

  2. #2
    Join Date
    Aug 2008
    Posts
    24

    Actually, I just need an answer to the first part:

    I need to select all values of "aKey" in TableB that do not exist in TableA.

    Thx!

  3. #3
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    select * from TableB
    where not exists
    (select 1 from TableA where TableA.aKey=TableB.aKey)

  4. #4
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    -- duplicate

  5. #5
    Join Date
    Aug 2008
    Posts
    24
    Quote Originally Posted by pdreyer
    select * from TableB
    where not exists
    (select 1 from TableA where TableA.aKey=TableB.aKey)
    Thanks pdeyer!

Posting Permissions

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