Briefly described, I have 2 tables that have 'equivalent' rows in each other. The equivalencies are maintained in a 3rd Mapping table (which maps ID A to ID B). In a view I want to create a consolidated view that shows:
- All entries that exist in Table A but have no equivalent in Table B (1 row each)
- All entries that exist in Table B but have no equivalent in Table A 开发者_如何学JAVA(1 row each)
- All entries that exist in both Table A and B (single row per A/B match)
It's easier to explain graphically...
I have the following scenario (shown in picture linked below):
Current Scenario
I'm sure this is much simpler than it seems - I've been chewing on this for a little while and can't get it workable.
How about just
select a.ID as A_ID, a.Desc as A_Desc, b.ID as B_ID, b.Desc as B_DESC
from Table_A as a left outer join Mapping_Table as m on a.ID = m.A_ID
full outer join Table_B as b on m.B_ID = b.ID
精彩评论