0 votes
in Sql by
What are the set operators in SQL?

1 Answer

0 votes
by
We use the set operators to merge data from one or more tables of the same kind. Although the set operators are like SQL joins, there is a significant distinction. SQL joins combine columns from separate tables, whereas SQL set operators combine rows from different queries. SQL queries that contain set operations are called compound queries. The set operators in SQL are categories into four different types:

SQL Interview Questions and Answers

A. UNION: It combines two or more results from multiple SELECT queries into a single result set. It has a default feature to remove the duplicate rows from the tables. The following syntax illustrates the Union operator:

SELECT columns FROM table1    

UNION    

SELECT columns FROM table2;    

B. UNION ALL: This operator is similar to the Union operator, but it does not remove the duplicate rows from the output of the SELECT statements. The following syntax illustrates the UNION ALL operator:

SELECT columns FROM table1    

UNION  ALL  

SELECT columns FROM table2;    

C. INTERSECT: This operator returns the common records from two or more SELECT statements. It always retrieves unique records and arranges them in ascending order by default. Here, the number of columns and data types should be the same. The following syntax illustrates the INTERSECT operator:

SELECT columns FROM table1    

INTERSECT  

SELECT columns FROM table2;    

D. MINUS: This operator returns the records from the first query, which is not found in the second query. It does not return duplicate values. The following syntax illustrates the MINUS operator:

SELECT columns FROM table1    

MINUS  

SELECT columns FROM table2;

Related questions

+2 votes
asked Jan 15, 2022 in Sql by GeorgeBell
0 votes
asked Sep 9, 2019 in Spark Sql by ivor2019
...