内部从多个表加入sqlite

时间:2013-04-25 20:18:34

标签: sql sqlite join

关注代码给我一个模糊的列DRIVER.driv_id错误,有什么帮助吗?

SELECT DRIVER.driv_id, DRIVER.firstName, DRIVER.surName, DRIVER.nationality,   TEAMSTANDING.teamName, RESULTS.points
FROM TEAMSTANDING INNER JOIN DRIVER ON TEAMSTANDING.driv_id=DRIVER.driv_id,
RESULTS INNER JOIN DRIVER ON RESULTS.driv_id=DRIVER.drv_id
WHERE TEAMSTANDING.comp_id=2
GROUP BY DRIVER.driv_id;

2 个答案:

答案 0 :(得分:5)

您必须尝试多次添加驱动程序表以便创建

SELECT 
    DRIVER.driv_id, DRIVER.firstName, DRIVER.surName, DRIVER.nationality,   TEAMSTANDING.teamName, RESULTS.points   
FROM 
    TEAMSTANDING
    INNER JOIN 
        DRIVER
ON 
        TEAMSTANDING.driv_id=DRIVER.driv_id
    INNER JOIN 
        RESULTS 
    ON 
        RESULTS.driv_id=DRIVER.drv_id
WHERE 
    TEAMSTANDING.comp_id=2
GROUP BY 
    DRIVER.driv_id;

答案 1 :(得分:0)

你的DRIVER在你的查询中加入了两次,所以你有两个别名为DRIVER的表,你使用了两个驱动程序。

将另一个表别名为别的,或者,如果不需要,则将其从JOIN中删除。