I have these two tables:
Table Author:
ID (INTEGER),
author_name (VARCHAR),
first_name (VARCHAR),
last_name (VARCHAR),
preferred_name (VARCHAR)
Table CoAuthored:
ID (INTEGER)
author1ID (INTEGER),
author2ID (INTEGER),
paper_ID (INTEGER) // (ID of the co-authored paper referenced by this link)
As you can see, both tables have a column 'ID', but they are unrelated.
However, when I use this query:
select author_name, count(*) as NumPapers from
(select * from Author as a join CoAuthored as c on a.ID = c.author1ID
union distinct
select * from Author as b join CoAuthored as d on b.ID = d.author2ID) as t1
group by author_name
order by NumPapers;
mySQL gves me an error saying: ERROR 1060 (42S21): Duplicate column name 'ID'
Why does this happen and how do I avoid it?