why would we use union when we can do the same using joins? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

why would we use union when we can do the same using joins?

25th Oct 2016, 2:21 PM
Sherin Sebastian
Sherin Sebastian - avatar
4 Answers
+ 16
union and join are completely different concepts. For union you need equal number of columns whose data types are also same. joins are much more useful and flexible. let's say you have an employee table with columns empid and deptno. you have another table department with columns deptno and deptname. if you want to find the department name for an employee you will do a join: select employee.empid, department.deptname from employee join department on employee.deptno=department.deptno. no way you can do this using union. happy learning!!
26th Oct 2016, 2:59 PM
ArchiC
+ 3
Union is combine of tables where as Join is to extract matching data of tables
27th Oct 2016, 5:04 PM
Raja Kishore Patnaik
Raja Kishore Patnaik - avatar
+ 1
good explanation
27th Oct 2016, 5:21 AM
Antonio Carrasco
Antonio Carrasco - avatar
0
yes UNION combines results of two or more queries into a single result.
2nd Jan 2017, 12:47 PM
saiprasad