2

我正在尝试将 3 个表与内部连接连接在一起。表 prod_num 和 usrs 由 usr_Id 关联,表 usrs 和 usr_Data 由 usr_Num 关联。所以表 1 和表 3 之间不相关,所以我想将表 3 加入 1 和 2 的结果,这就是我想要做的:

USE Puzzle
SELECT a.Name, a.Id, b.Id, c.Email
FROM prod_num a INNER JOIN usrs b
ON a.usr_Num = b.usr_Num<br>FROM usrs b INNER JOIN usr_Data c
ON b.usr_Id = c.usr_Id

如何从先前加入的结果进行加入?

4

3 回答 3

4

您应该只使用一个FROM关键字,因为JOINs 是FROM子句的一部分,

SELECT  a.Name, 
        a.Id, 
        b.Id, 
        c.Email
FROM    prod_num a 
        INNER JOIN usrs b 
            ON a.usr_Num = b.usr_Num
        INNER JOIN usr_Data c
            ON b.usr_Id = c.usr_Id

要进一步了解有关联接的更多信息,请访问以下链接:

于 2013-03-12T12:11:16.833 回答
3

尝试这个:

USE Puzzle
SELECT a.Name, a.Id, b.Id, c.Email
FROM prod_num a
INNER JOIN usrs b ON a.usr_Num = b.usr_Num
INNER JOIN usr_Data c ON b.usr_Id = c.usr_Id

FROM您的语句之间有一个额外的子句JOIN

于 2013-03-12T12:11:30.220 回答
2

你可以这样做:

USE Puzzle
SELECT 
     a.Name, 
     a.Id, 
     b.Id, 
     c.Email
FROM prod_num a 
INNER JOIN usrs b ON a.usr_Num = b.usr_Num
INNER JOIN usr_Data c ON b.usr_Id = c.usr_Id
于 2013-03-12T12:14:51.263 回答