What is different between union and minus?

Answer Posted / elumalai d

UNOIN:- It returns all the records from both tables without duplicates.
Example:-
A={1,2,3,4}
B={2,3,4,5,6}
AUB={1,2,3,4,5,6}

CREATE TABLE question36 (empid NUMBER);
CREATE TABLE quest36 (empid NUMBER);

INSERT INTO question36 VALUES(1);
INSERT INTO question36 VALUES(2);
INSERT INTO question36 VALUES(3);
INSERT INTO question36 VALUES(4);

INSERT INTO quest36 VALUES(2);
INSERT INTO quest36 VALUES(3);
INSERT INTO quest36 VALUES(4);
INSERT INTO quest36 VALUES(5);
INSERT INTO quest36 VALUES(6);
COMMIT;

SELECT empid FROM question36
UNION
SELECT empid FROM quest36;

EMPID
---------
1
2
3
4
5
6

DELETE FROM question36;
DELETE FROM quest36;
COMMIT;

MINUS:- It returns table A values not available in table B.
Example:-
A={1,2,3,4}
B= {2,3,5}
A-B={1,4}

INSERT INTO question36 VALUES(1);
INSERT INTO question36 VALUES(2);
INSERT INTO question36 VALUES(3);
INSERT INTO question36 VALUES(4);

INSERT INTO quest36 VALUES(2);
INSERT INTO quest36 VALUES(3);
INSERT INTO quest36 VALUES(5);
COMMIT;

SELECT empid FROM question36
MINUS
SELECT empid FROM quest36;

EMPID
---------
1
4

DROP TABLE question36;
DROP TABLE quest36;

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what are the disadvantages of mysql? : Sql dba

658


What is the purpose of my sql?

599


Define a temp table?

651


Is grant a ddl statement?

535


What is not null in sql?

668






how to use case expression? : Sql dba

648


What is the difference between microsoft sql and mysql?

610


What is a ddl command?

622


what happens if you no create privilege in a database? : Sql dba

621


What is the difference between functions, procedures, and packages in pl/sql?

597


how to rename an existing column in a table? : Sql dba

593


Does varchar need length?

612


Is primary key is clustered index?

611


what are date and time intervals? : Sql dba

645


What is data manipulation language?

780