gel*_*ne1 2 sql postgresql inner-join duplicates
我有两个表都包含 Artistid 列。当我使用内部联接来组合两个表时,我得到一个结果表,其中包含两次artistid列,使我无法检索artistid(因为它抱怨不明确)。如何确保合并表格后不会再次出现相同的列?
这是我使用的查询:
SELECT * FROM artist a INNER JOIN track b ON a.artistid = b.artistid
Run Code Online (Sandbox Code Playgroud)
如果唯一的重复列是artistid(用于连接的列),您可以使用:
SELECT *
FROM artist
JOIN track USING(artistid);
Run Code Online (Sandbox Code Playgroud)
否则,您需要指定所有列并根据需要添加别名:
SELECT a.col1 AS alias, a.col2, ..., b.col1 AS alias2, b.col2, ...
FROM artist a
INNER JOIN track b ON a.artistid = b.artistid
Run Code Online (Sandbox Code Playgroud)