in Technology by
What are UNION, MINUS and INTERSECT commands?

1 Answer

0 votes
by

The UNION operator combines and returns the result-set retrieved by two or more SELECT statements.
The MINUS operator in SQL is used to remove duplicates from the result-set obtained by the second SELECT query from the result-set obtained by the first SELECT query and then return the filtered results from the first.
The INTERSECT clause in SQL combines the result-set fetched by the two SELECT statements where records from one match the other and then returns this intersection of result-sets.

Certain conditions need to be met before executing either of the above statements in SQL -

SELECT name FROM Students 	 /* Fetch the union of queries */
UNION
SELECT name FROM Contacts;

SELECT name FROM Students 	 /* Fetch the union of queries with duplicates*/
UNION ALL
SELECT name FROM Contacts;
SELECT name FROM Students 	 /* Fetch names from students */
MINUS 				/* that aren't present in contacts */
SELECT name FROM Contacts;
SELECT name FROM Students 	 /* Fetch names from students */
INTERSECT 			/* that are present in contacts as well */
SELECT name FROM Contacts;
    • Each SELECT statement within the clause must have the same number of columns
    • The columns must also have similar data types
    • The columns in each SELECT statement should necessarily have the same order

Related questions

0 votes
    In a convex hexagon two diagonals are drawn at random. The probability that the diagonals intersect at an interior ... none of these Select the correct answer from above options...
asked Nov 15, 2021 in Education by JackTerrance
0 votes
    What are the purposes of up, run, and start commands of docker compose?...
asked Jun 20, 2021 in Technology by JackTerrance
0 votes
    What are the Spring Boot CLI commands?...
asked Jul 7, 2021 in Technology by JackTerrance
0 votes
    While working on the Subversion, what are the various commands which you have used frequently for handling the changes made to the documents?...
asked Feb 18, 2021 in Technology by JackTerrance
0 votes
    What are the PowerCenter commands that can be used in Informatica?...
asked Dec 28, 2020 in Technology by JackTerrance
0 votes
    Why update strategy and union transformations are Active? Explain with examples....
asked Mar 28, 2021 in Technology by JackTerrance
0 votes
    When I run the server using php bin/console server:run I get the following error. There are no ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 1, 2022 in Education by JackTerrance
0 votes
    If commands are stored in an external file, say commands.R in the working directory work, they may be executed ... of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    commands in the ribbon are divided into groups ( ture or false ) Select the correct answer from above options...
asked Nov 26, 2021 in Education by JackTerrance
0 votes
    What are Hadoop HDFS Commands?...
asked Aug 3, 2021 by JackTerrance
0 votes
    What are the demands of Trade Union Movement? Please answer the above question....
asked Aug 14, 2022 in Education by JackTerrance
0 votes
    What is the difference between stats and eventstats commands?...
asked Oct 31, 2020 in Technology by JackTerrance
0 votes
    What is meant by Ad-Hoc commands? Give one example....
asked Jan 28, 2023 in Technology by JackTerrance
0 votes
    Through ChatOps, communication can be bi-directional, that is, users can submit commands from the chat room to the bots, ... status to the chat room directly. A. True B. False...
asked Dec 23, 2022 in Technology by JackTerrance
0 votes
    Write the commands to check how much memory is being used by Linux?...
asked Jan 24, 2021 in Technology by JackTerrance
...