finding missing rows with outer join?

  • I have two identically structured tables, A and B. "A" has the correct records, "B" is like "A" but has some rows missing. The first column is a unique identifier key. How do I determine what the missing rows are? This is a pretty fundamental database activity but I can't figure out how to do it in SQL server. I can do an outer join on A & B, returning both NULL and regular rows, but there seems to be no way to see the unique identifier from table "A" that corresponds to a null in "B".

  • SELECT A.*

    FROM A

    LEFT OUTER JOIN B ON B.key = A.key

    WHERE B.key IS NULL

    will show all rows in A that do not have a corresponding key in B

    Far away is close at hand in the images of elsewhere.
    Anon.

  • Slight addition... I want to see JUST the rows that are missing... not all rows, NULL or not. So I would like to list the keys from "A" that correspond to the missing rows in "B".

  • The sql should do that. e.g. if A contains keys 1,2,3 and B contains 1,3 then the query will return 2 only.

    Far away is close at hand in the images of elsewhere.
    Anon.

  • It works great. Thanks!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply