Matin Lotfaliee Matin Lotfaliee - 4 months ago 18
MySQL Question

#1060 - Duplicate column name

Why does this query errors

(1060) Duplicate column name 'studentID'
in MySQL? How can I prevent it?

CREATE TEMPORARY TABLE tempTable
select * from member_infos
join contact_infos on member_infos.studentID=contact_infos.studentID

Answer

If you use MySQL's USING clause (alternative to ON), it will only product one copy of the shared field used to join those tables in the results of the SELECT.

If there are other fields sharing names, USING cannot help you; you will need to list out all fields explicitly in order to exclude (or alias) fields with the same name.

USING is covered in the MySQL JOIN documention.

Comments