在多个表上使用JOIN进行查询

时间:2014-08-03 14:40:38

标签: sql

我的这个小查询工作正常:

SELECT * FROM Components AS T1
WHERE Cost=null or Cost=''
Order by Code

现在我还要抓住提交的#34;描述"来自其他代码= code

的表
SELECT * FROM Components AS T1
WHERE Cost=null or Cost=''

LEFT JOIN on Table_321 AS T2
where T1.Code=T2.Code

Order by Code

但它给了我一个sintax错误" LEFT"我无法解决这个问题,我不确定这样的JOIN是否是正确的方法。一些帮助表明我如何解决问题将非常感激。此外,我还有另一张表" Table_621,我需要从中获取描述。如何在查询中添加第二个表?

3 个答案:

答案 0 :(得分:1)

SELECT * FROM Components T1
LEFT JOIN Table_321 T2 ON T1.Code=T2.Code
LEFT JOIN Table3 T3 ON T3.Code = T1.Code
WHERE T1.Cost=null or T1.Cost=''
ORDER BY T1.Code

答案 1 :(得分:0)

SELECT * FROM Components AS T1
LEFT JOIN Table_321 AS T2
ON T1.Code=T2.Code
WHERE Cost=null or Cost=''

Order by Code

答案 2 :(得分:0)

顺序不明确在下面的情况:

SELECT * FROM Components T1
    LEFT JOIN Table_321 T2
    ON T1.Code=T2.Code
    WHERE T1.Cost=null or T1.Cost=''
    ORDER BY Code

试试这个

SELECT * FROM Components T1
        LEFT JOIN Table_321 T2
        ON T1.Code=T2.Code
        WHERE T1.Cost=null or T1.Cost=''
        ORDER BY T2.Code --or T1.Code