Can you explain what is the difference between UNION and Join?

0 votes
I have a doubt regarding union and join operation?

can you please explain with example?
May 30 in Database by Sahana
98 views

1 answer to this question.

0 votes

Hi Sahana, 

I got your doubt, Checkout these queries I hope this will help you out,

Suppose we have two tables:

1.Customers 

2.City

If we use 'Union' that time it will return all the distinct value from both of the table

SELECT City FROM Customers
UNION
SELECT City FROM Suppliers
ORDER BY City;

Join:

Here is the list of joins we can do to manipulate the data.

1. Inner join

2. Right join

3. Left join

4. Full outer join 

5. Self join

1.Inner join: INNER JOIN  selects records that have matching values in both tables.

2. Right join: RIGHT JOIN returns all records from the right table (table2), and the matched records from the left table (table1)

3.Left join:  LEFT JOIN keyword returns all records from the left table (table1), and the matched records from the right table (table2)

4. Full outer join: FULL OUTER JOIN return all records when there is a match in either left (table1) or right (table2) table records

5. Self join:  self JOIN is a regular join, But the table is joined with itself.

Thank you,

answered May 30 by sampriti
• 1,100 points

Related Questions In Database

+1 vote
1 answer

Difference between cross join and natural join

The cross join produces the cross product ...READ MORE

answered Oct 12, 2018 in Database by DataKing99
• 8,130 points
3,215 views
+1 vote
1 answer

What is the AND operator?

The AND operator is used to filter ...READ MORE

answered Nov 30, 2018 in Database by darklord
• 6,190 points
62 views
0 votes
1 answer

What is the rule to use group by, having and where clause?

Hi samar, this is a very common mistake ...READ MORE

answered Jul 2 in Database by anonymous
62 views
0 votes
1 answer

Do I need to add primary key in each and every table?

Hi Shraddha, You have a doubt to add ...READ MORE

answered May 29 in Database by sampriti
• 1,100 points
54 views
0 votes
1 answer

How to sort the data in sql ?

Hi Akash,  If you want to sort ...READ MORE

answered May 29 in Database by sampriti
• 1,100 points
38 views
+1 vote
1 answer

Do I need to mention primary key for each table?

Hi Pritha, First, there is no hard and ...READ MORE

answered Jul 4 in Database by sampriti
• 1,100 points
75 views
0 votes
1 answer

Want a command to be executed in Salt only if a directory is empty

You should consider using this inside your ...READ MORE

answered Jun 12, 2018 in DevOps Tools by Damon Salvatore
• 5,510 points
48 views
0 votes
1 answer

Can you please explain the difference between inner join and outer join in database?

Hi Suraj, You have a doubt regarding inner join ...READ MORE

answered May 28 in Database by sampriti
• 1,100 points
104 views
0 votes
1 answer

What is the best way to fetch data from table?

Hey Shraddha, I understand your doubts about fetching ...READ MORE

answered May 24 in Database by sampriti
• 1,100 points
48 views