Table 1 Table 2 Number | Code Code | Description 1234 A A Something 1235 B C Something else 1246 C D Something other 1247 A 1248 B 1249 A
我想找到不同的代码值并获得如下返回:
1 | 2 ------- A A B C C D
解决方法
在适当的RDBMS中:
SELECT T1.Code,T2.Code FROM (SELECT DISTINCT Code FROM Table1) T1 FULL OUTER JOIN (SELECT DISTINCT Code FROM Table2) T2 ON T1.Code = T2.Code
SELECT T1.Code,T2.Code FROM Table1 T1 LEFT OUTER JOIN Table2 T2 ON T1.Code = T2.Code UNION SELECT T1.Code,T2.Code FROM Table1 T1 RIGHT OUTER JOIN Table2 T2 ON T1.Code = T2.Code