我有这个代码
select people_id,first_name
FROM people , PUBAUTHOR_PEOPLE
WHERE people.people_id = PUBAUTHOR_PEOPLE. people_id
并且它表示模糊定义的列是否有人知道为什么以及如何解决这个问题?
答案 0 :(得分:1)
您应该在您的库存名称之前添加表名称,如下所示
select people.people_id,people.first_name
FROM people , PUBAUTHOR_PEOPLE
WHERE people.people_id = PUBAUTHOR_PEOPLE. people_id
我建议你使用如下的别名来使代码更具可读性
select p.people_id,p.first_name
FROM people p, PUBAUTHOR_PEOPLE pp
WHERE p.people_id = pp.people_id
我还建议你使用如下的连接
select p.people_id,p.first_name
FROM people p
join PUBAUTHOR_PEOPLE pp on p.people_id = pp.people_id
现在更具可读性,不是吗?
答案 1 :(得分:1)
它抱怨,因为两个表都有一个名为'people_id'的列,所以你必须指定从哪个表中读取它(即使它因连接条件而相同),所以类似于:
SELECT people.people_id,
first_name
FROM people, PUBAUTHOR_PEOPLE
WHERE people.people_id = PUBAUTHOR_PEOPLE.people_id