我希望比较两组数据并显示两组的完整并集,并添加列以显示行是否出现在集合 1、集合 2 或两者中。我正在使用 T-SQL
Table A
|[ID] | [Movie] | [Year] |
|-----|---------|--------|
| 1 | Movie1 | Year1 |
| 2 | Movie2 | Year2 |
| 3 | Movie3 | Year3 |
Table B
|[ID] | [Movie] | [Year] |
|-----|---------|--------|
| 2 | Movie2 | Year2 |
| 3 | Movie3 | Year3 |
| 4 | Movie4 | Year4 |
Desired Result:
|[ID] | [Movie] | [Year] | [In Set A?] | [In Set B?] |
|-----|---------|--------|-------------|-------------|
| 1 | Movie1 | Year1 | Yes | No |
| 2 | Movie2 | Year2 | Yes | Yes |
| 3 | Movie3 | Year3 | Yes | Yes |
| 4 | Movie4 | Year4 | No | Yes |
这可以在 SQL 中完成吗?我会满足于让添加的列只是输出为 A、B 或两者的 1 列。