Reputation: 199
I have two tables both containing the column artistid. When I use inner join to combine the two tables I get a resulting table that contains the column artistid twice making me unable to retrieve the artistid (as it complains about being ambiguous). How do I make sure the same column doesn't reappear after combining the tables?
This is the query I used:
SELECT * FROM artist a INNER JOIN track b ON a.artistid = b.artistid
Upvotes: 2
Views: 2330
Reputation: 120
please do not use inner join. I had the similar problem creating report. Use instead. SELECT track from atrist where a.artistid = b.artistid
Upvotes: -1
Reputation: 175566
If the only duplicate column is artistid
(column that you use for joining) you can use:
SELECT *
FROM artist
JOIN track USING(artistid);
Otherwise you need to specify all column and add aliases if needed:
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
Upvotes: 5