开发者

How to join three different tables in mysql with no common field amongst them all

开发者 https://www.devze.com 2023-03-26 10:43 出处:网络
If I开发者_如何学C have table 1 with fields Groupid and Branchid amonst others, table 2 with fields Group id and Groupname amongst others and table 3 with fields Branchid and Branchname amongst others

If I开发者_如何学C have table 1 with fields Groupid and Branchid amonst others, table 2 with fields Group id and Groupname amongst others and table 3 with fields Branchid and Branchname amongst others, how do I join these tables?

natural join does not work.


SELECT foo
FROM Table1
    JOIN Table2 ON Table2.GroupID = Table1.GroupID
    JOIN Table3 ON Table3.BranchID = Table1.BranchID


This is what the query should likely be typically. Is this different that what you have?

(SQL Server syntax)

SELECT Column1, Column2...
FROM GroupBranch_Rel
  INNER JOIN Groups
    ON Groups.GroupID = GroupBranch_Rel.GroupID
  INNER JOIN Branches
    ON Branches.BranchID = GroupBranch_Rel.BranchID
0

精彩评论

暂无评论...
验证码 换一张
取 消