JOIN in SQL is used to combine data from many tables based on a matched condition between them. The data combined using JOIN statement results into new columns.
Consider the two tables:
sql> SELECT Boys.Name, Boys.Age, Girls.Address, FROM Boys INNER JOIN Girls ON Boys.Rollno = Girls.Rollno;
The resultant table is:
UNION in SQL is used to combine the result-set of two or more SELECT statements. The data combined using UNION statement is into results into new distinct rows.
sql> SELECT Name FROM Boys WHERE Rollno < 16 UNION SELECT Name FROM Girls WHERE Rollno > 9
The resultant table is:
Difference between JOIN and UNION in SQL :
|JOIN combines data from many tables based on a matched condition between them.||SQL combines the result-set of two or more SELECT statements.|
|It combines data into new columns.||It combines data into new rows|
|Number of columns selected from each table may not be same.||Number of columns selected from each table should be same.|
|Datatypes of corresponding columns selected from each table can be different.||Datatypes of corresponding columns selected from each table should be same.|
|It may not return distinct columns.||It returns distinct rows.|
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Difference between Natural join and Cross join in SQL
- Difference between Natural join and Inner Join in SQL
- Difference between Inner Join and Outer Join in SQL
- Difference between Structure and Union in C
- Difference between Left, Right and Full Outer Join
- Difference between Lossless and Lossy Join Decomposition
- SQL | Join (Cartesian Join & Self Join)
- Inner Join vs Outer Join
- SQL Join vs Subquery
- Join statement in JCL
- How to use .join() with push and replace together?
- Join algorithms in Database
- Union process in DFA
- SQL | Union Clause
- SQL | Join (Inner, Left, Right and Full Joins)
- Should I join a mass recruiter or a startup?
- Lossless Join and Dependency Preserving Decomposition
- Join operation Vs Nested query in DBMS
- Differences between wait() and join() methods in Java
- strings.Join() Function in Golang With Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : dhruv5819