内部联接创建重复列

inner join creating a duplicate column

我有两个 table 都包含 artistid 列。当我使用内部联接将两个 table 组合起来时,我得到一个结果 table,其中两次包含 artistid 列,这使我无法检索 artistid(因为它抱怨模棱两可)。如何确保合并 tables 后同一列不再出现?
这是我使用的查询:

SELECT * FROM artist a INNER JOIN track b ON a.artistid = b.artistid

如果唯一的重复列是 artistid(您用于连接的列),您可以使用:

SELECT * 
FROM artist  
JOIN track USING(artistid);

SqlFiddleDemo

否则您需要指定所有列并根据需要添加别名:

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

请不要使用内连接。我在创建报告时遇到了类似的问题。改用。 SELECT track from atrist where a.artistid = b.artistid