sqldatabasepostgresqlselectambiguous

SQL column reference "id" is ambiguous


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.

If I try the same SELECT, but I only ask for name and not for id also, it works.

Any suggestions?


Solution

  • 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;