我正在通过大查询来实现以下目标,但是在标准SQL方言中却难以解决语法
SELECT DB.Table1.Key1,DB.Table3.Name ]
Where Table1.Key1=Table2.Key1, Table2.Key2=Table3.Name
以下是表格摘要
+---------+-----------+-----------+
| Tabel 1 |Table 2 |Table 3 |
| key1(PK)| Key1(FK) | Key2(FK) |
| | Key2(PK) | Name |
+---------+-----------+-----------+
SELECT key
FROM `DB.Table1`
union DISTINCT
SELECT key, Key2
from
`DB.Table2`
union DISTINCT
SELECT Key2
from`DB3`
答案 0 :(得分:1)
使用标准sql模式,通过使用join尝试如下所示
SELECT Table1.Key1,Table3.Name
from Table1 join Table2
on Table1.Key1=Table2.Key1
join Table3 on Table2.Key2=Table3.Name