Vikas Rajput
Vikas Rajput

@vikasrajputin

6 تغريدة Dec 06, 2022
Introduction to UNION, MINUS and INTERSECT commands
in SQL for an Absolute Beginner:
🧵👇
1. UNION
- UNION is used to combine records from all SELECT queries without repeating duplicate records.
- UNION ALL combines results from all queries with all duplicate records.
Eg:
Given EMPLOYEE and DEPARTMENT tables.
We can use UNION and UNION ALL as shown below:
2. MINUS
- MINUS returns all records from the first query and subtracts similar records from the next query.
Eg:
Given EMPLOYEE and DEPARTMENT tables.
We can use MINUS as shown below:
3. INTERSECT
- INTERSECT only returns the common records in both queries.
Eg:
Given EMPLOYEE and DEPARTMENT tables.
We can use INTERSECT as shown below:
That's a wrap!
I've purposefully not shown the output of these queries,
I want you to try it yourself and let me know your feedback in the comments.
If you loved reading this thread, you might enjoy reading my previous thread on SQL:
Namaste, I'm Vikas
Every Mon, Wed & Friday - I write a thread on Backend Development.
1. Follow me @vikasrajputin to read all my future threads
2. RT the tweet below it helps me motivate to create more content like this

جاري تحميل الاقتراحات...