t-sql - find differences for pk's in a single table (Self join?)

Posted by Pace on Stack Overflow See other posts from Stack Overflow or by Pace
Published on 2010-06-02T08:38:07Z Indexed on 2010/06/02 8:53 UTC
Read the original article Hit count: 195

Filed under:
|

Hi Experts,

My situation is this. I have a table of products with a pk "Parent" which has "Components" The data looks something like this

Parent(PK)    Component
Car1          Wheel
Car1          Tyre
Car1          Roof
Car2          Alloy
Car2          Tyre 
Car2          Roof
Car3          Alloy
Car3          Tyre
Car3          Roof 
Car3          Leather Seats

Now what I want to do is some query that I can feed two codes in and see the differences... IE If I feed in "Car1", "Car2" it would return something like;

Parent       Component
Car1         Wheel
Car2         Alloy

As this is the difference between the two. If I said "Car1", "Car3" I would expect;

Parent       Component
Car1         Wheel
Car3         Alloy
Car3         Leather Seats

Your help with this matter would be greatly appreciated.

© Stack Overflow or respective owner

Related posts about sql

Related posts about tsql