我试图找出为什么我在此查询中获得重复的列名称。我觉得我正好为我的搜索字词加前缀,不应该收到此错误。请指教。
模型
Emp(eid:integer, ename:varchar, age:integer, salary:integer)
Works(did:integer, eid:integer)
Dept(did:integer, managerid:integer) //managerid is foreign key to eid
查询
CREATE VIEW Manager AS
SELECT e.eid, e.ename, e2.eid, e2.ename
FROM Emp AS e,
Dept AS d
LEFT JOIN Emp AS e2 ON d.managerid = e2.eid;
答案 0 :(得分:1)
在您的字段中尝试一些ALIAS。见下文:
CREATE VIEW Manager AS
SELECT
e.eid AS eid1,
e.ename AS ename1,
e2.eid AS eid2,
e2.ename AS ename2
FROM Emp AS e,
Dept AS d
LEFT JOIN Emp AS e2 ON d.managerid = e2.eid2;