简体   繁体   English

列含糊不清的错误

[英]column ambigously defined error

i have this code 我有这个代码

select people_id,first_name 
FROM people , PUBAUTHOR_PEOPLE 
WHERE people.people_id = PUBAUTHOR_PEOPLE. people_id 

and it says column ambigously defined does anybody know why and how to fix that? 它说列定义不明确,有人知道为什么以及如何解决这个问题吗?

You should add table name before your coulmn names as below 您应该在表名之前添加表名,如下所示

select people.people_id,people.first_name 
FROM people , PUBAUTHOR_PEOPLE 
WHERE people.people_id = PUBAUTHOR_PEOPLE. people_id 

I recommended you to use aliases as below to make code more readable 我建议您使用以下别名来使代码更具可读性

select p.people_id,p.first_name 
FROM people p, PUBAUTHOR_PEOPLE pp
WHERE p.people_id = pp.people_id 

I also recommended you to use joins as below 我还建议您使用以下联接

select p.people_id,p.first_name 
FROM people p
join PUBAUTHOR_PEOPLE pp on p.people_id = pp.people_id

It is more readable now, isn't it? 现在它更具可读性,不是吗?

It's complaining because both tables have a column called 'people_id', so you have to specify which table to read it from (even though it will be the same because of the join condition), so something like: 之所以抱怨,是因为两个表都有一个名为“ people_id”的列,因此您必须指定要从哪个表读取数据(即使由于连接条件而相同),如下所示:

SELECT      people.people_id,
            first_name 

FROM        people, PUBAUTHOR_PEOPLE 

WHERE       people.people_id = PUBAUTHOR_PEOPLE.people_id 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM