如何在mysql中连接三个或更多表

时间:2012-06-08 12:01:44

标签: mysql

我有三个表,我想要从中检索值,我使用后面的查询给出了错误,有人能告诉我什么是错的吗?

SELECT a.VISITOR_TEXT,a.COMPANY_TEXT,a.CONTACT,a.PERSON_TO_MEET,a.DEPARTMENT_TEXT,a.FLOOR,b.BELONGING_T
YPE,b.BELONGING_TEXT ,a.INTIME, c.EXIT_TIME FROM tm_visitor a  LEFT JOIN tm_belonging b , tm_exit c ON a.ID=b.
BID AND a.ID=c.ID;

3 个答案:

答案 0 :(得分:0)

SELECT a.VISITOR_TEXT,a.COMPANY_TEXT,a.CONTACT,a.PERSON_TO_MEET,a.DEPARTMENT_TEXT,a.FLOOR,b.BELONGING_TYPE,b.BELONGING_TEXT ,a.INTIME, c.EXIT_TIME FROM tm_visitor a  
LEFT JOIN tm_belonging b ON a.ID=b.BID 
LEFT JOIN tm_exit c ON a.ID=c.ID;

答案 1 :(得分:0)

这就是你要找的东西:

SELECT  a.VISITOR_TEXT,
        a.COMPANY_TEXT,
        a.CONTACT,
        a.PERSON_TO_MEET,
        a.DEPARTMENT_TEXT,
        a.FLOOR,
        b.BELONGING_TYPE,
        b.BELONGING_TEXT,
        a.INTIME,
        c.EXIT_TIME 
FROM    tm_visitor a  
        LEFT JOIN tm_belonging b ON b.BID = a.id
        LEFT JOIN tm_exit c ON c.ID = a.ID

答案 2 :(得分:0)

您不能将,与联接语法一起使用。仅在from语法中。使用

SELECT  a.VISITOR_TEXT, a.COMPANY_TEXT,a.CONTACT, a.PERSON_TO_MEET,a.DEPARTMENT_TEXT, a.FLOOR,b.BELONGING_TYPE,b.BELONGING_TEXT, a.INTIME, c.EXIT_TIME 
FROM tm_visitor a  
LEFT JOIN tm_belonging b  ON a.ID=b.BID
left join tm_exit c ON a.ID=c.ID