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.

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

hey thanks for that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.