I have a table like
col1 col2 col3
abc 123 A
abc 345 B
def 567 A
ghi 890 B
I want to have the data in one row related to an element. Col3 is the discriminator element. Only the ‘A’ and ‘B’ rows are related. Result should look like
col1 col2A col2B
abc 123 345
def 567 --
ghi -- 890
How can i do that??
That might not be case to use self join. This will work for the data you posted:
Of course, if you have data like below, it would fail:
Then again, not only the query would fail, but your whole business rule would fail if you have data like this.