0

Hi,

i am relatively new to mysql just learning the basics really.

i have googled this but there is so many discussions on it.

Could someone just give a simplified answer to what is the difference between using Union or Join and when would you use one or the other?

thank you all.

2
Contributors
2
Replies
6
Views
7 Years
Discussion Span
Last Post by andydeans
0

A union is used when a set of columns with the same name and same data-type are present in two tables (or the same table but two aliases, and you are querying on two exclusive sets of conditions) and you wish to present the combined data extracted from each table.

A join is used when you have a primary key in one table that is a foreign key in another table and you wish to pull the data from one table that matches the key from the other table.
eg emp{empID, name, address, universityID, etc}
University (universityID, uName, uAddress, etc}

and you want the employee's name address and the name and address of the university that they attended.

So you join the two tables on employee.universityID = university.univeristyID

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.