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, 2019 in Database by Sahana
1,380 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, 2019 by sampriti
• 1,120 points

Related Questions In Database

0 votes
1 answer

What is the difference between SQL, PL-SQL and T-SQL?

SQL SQL is the standard language for relational ...READ MORE

answered Feb 16, 2022 in Database by Vaani
• 7,070 points
914 views
0 votes
1 answer

What is the difference between HAVING and WHERE in SQL?

HAVING: It is used to check after the aggregation ...READ MORE

answered Feb 17, 2022 in Database by Vaani
• 7,070 points
789 views
0 votes
0 answers

What is the difference between drop table and delete table in SQL Server?

What is the distinction between the following ...READ MORE

Aug 9, 2022 in Database by Kithuzzz
• 38,000 points
839 views
0 votes
0 answers

What is the difference between varchar and nvarchar?

Is it only that multibyte characters are ...READ MORE

Aug 30, 2022 in Database by Kithuzzz
• 38,000 points
655 views
0 votes
0 answers

What's the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN and FULL JOIN?

What's the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN and FULL ...READ MORE

Aug 13, 2022 in Database by Kithuzzz
• 38,000 points
500 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, 2019 in Database by sampriti
• 1,120 points
1,497 views
0 votes
1 answer

How to sort the data in sql ?

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

answered May 29, 2019 in Database by sampriti
• 1,120 points
1,130 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, 2019 in Database by sampriti
• 1,120 points
1,022 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, 2019 in Database by sampriti
• 1,120 points
1,166 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 25, 2019 in Database by sampriti
• 1,120 points
2,046 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP