SELECT a.ID,
e.name object,
a.date,
b.name R1,
c.name R2,
d.`u-name` R3
FROM table1 a
INNER JOIN table2 b
ON a.r1 = b.object
INNER JOIN table2 c
ON a.r2 = c.object
INNER JOIN table2 e
ON a.object = e.object
INNER JOIN table3 d
ON a.r3 = d.`u-id`
爲了進一步獲得更多的知識有關加入,請訪問以下鏈接:
上面的查詢使用INNER JOIN
僅table1
如果合適的話所有字段爲不可爲空。當其中一個是可以爲空時並且您想要返回table1
的所有列表,請使用LEFT JOIN
而不是INNER JOIN
。
「..Also新表應該這樣做只有一個(大)查詢來創建。」
CREATE TABLE tableNameHere(col1 INT,....) -- list of columns
AS
SELECT a.ID,
e.name object,
a.date,
b.name R1,
c.name R2,
d.`u-name` R3
FROM table1 a
INNER JOIN table2 b
ON a.r1 = b.object
INNER JOIN table2 c
ON a.r2 = c.object
INNER JOIN table2 e
ON a.object = e.object
INNER JOIN table3 d
ON a.r3 = d.`u-id`
你是不是缺少一個更加入?就像「物體」一樣? – Brian 2013-05-12 02:06:43
你是對的。我會更新答案。 – 2013-05-12 02:11:36
看到我更新的答案。 – 2013-05-12 02:12:59