SQL Postgresql 列引用“id”不明确
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9821121/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Postgresql column reference "id" is ambiguous
提问by Fofole
I tried the following select:
我尝试了以下选择:
SELECT (id,name) FROM v_groups vg
inner join people2v_groups p2vg on vg.id = p2vg.v_group_id
where p2vg.people_id =0;
and I get the following error column reference "id" is ambiguous.
我得到以下错误列引用“id”不明确。
Thing is if I try the same select but I only ask for (name) , and not for id also, it works. I'm new to this and maybe I am missing something obvious. Any suggestions?
事情是,如果我尝试相同的选择,但我只要求 (name) ,而不是 id ,它可以工作。我对此很陌生,也许我错过了一些明显的东西。有什么建议?
Thanks.
谢谢。
回答by JScoobyCed
You need the table name/alias in the SELECTpart (maybe (vg.id, name)) :
您需要部分中的表名/别名SELECT(可能(vg.id, name)):
SELECT (vg.id,name) FROM v_groups vg
inner join people2v_groups p2vg on vg.id = p2vg.v_group_id
where p2vg.people_id =0;
回答by dweeves
I suppose your p2vg table has also an id field , in that case , postgres cannot find if the id in the SELECTrefers to vg or p2vg.
我想你的 p2vg 表也有一个 id 字段,在这种情况下,postgres 无法找到 id 中的 id 是SELECT指 vg 还是 p2vg。
you should use SELECT(vg.id,vg.name)to remove ambiguity
你应该SELECT(vg.id,vg.name)用来消除歧义
回答by Janaki
SELECT (vg.id, name) FROM v_groups vg
INNER JOIN people2v_groups p2vg ON vg.id = p2vg.v_group_id
WHERE p2vg.people_id = 0;
回答by Alex Mack
SELECT vg.id,
vg.name
FROM v_groups vg INNER JOIN
people2v_groups p2vg ON vg.id = p2vg.v_group_id
WHERE p2vg.people_id = 0;

