开发者

Consolidate 2 tables via a mapping table - Full Joins?

开发者 https://www.devze.com 2023-01-27 08:46 出处:网络
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 consolid

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

Consolidate 2 tables via a mapping table - Full Joins?

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号