Postgresql column reference “id” is ambiguous

前端 未结 4 894
粉色の甜心
粉色の甜心 2021-02-04 23:18

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;
相关标签:
4条回答
  • 2021-02-05 00:06
    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;
    
    0 讨论(0)
  • 2021-02-05 00:07
    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;
    
    0 讨论(0)
  • 2021-02-05 00:08

    You need the table name/alias in the SELECT part (maybe (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;
    
    0 讨论(0)
  • 2021-02-05 00:15

    I suppose your p2vg table has also an id field , in that case , postgres cannot find if the id in the SELECT refers to vg or p2vg.

    you should use SELECT(vg.id,vg.name) to remove ambiguity

    0 讨论(0)
提交回复
热议问题