我不是很习惯 SQL 查询,但是我必须做这个涉及很多表的查询。他们来了:
(注:id
始终是PRIMARY KEY
。)
A(id, name)
B(id, title, a_id, FOREIGN KEY(a_id) REFERENCES A(id))
C(id, d_id, b_id, FOREIGN KEY (d_id) REFERENCES D(id), FOREIGN KEY REFERENCES (b_id) REFERENCES B(id))
D(id, content)
E(id d_id, a_id, c_id, FOREIGN KEY (d_id) REFERENCES D(id), FOREIGN KEY (a_id) REFERENCES A(id), FOREIGN KEY (C_id) REFERENCES c(id))
我需要从 table 中检索所有行E
。
这是我写的查询:
SELECT *
FROM E
LEFT JOIN D ON E.d_id = D.id
LEFT JOIN A ON E.a_id = A.id
LEFT JOIN B LEFT JOIN A ON B.a_id = B.id
ON C.b_id = B.id
LEFT JOIN D ON C.d_id = D.id
ON E.c_id = C.id
但它给了我一个运行时错误:
不明确的列名“ID”;
谁能给我一个提示来解决这个问题?