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

Why is sharding used?

554


how to delete duplicate rows from a join tables(I have three tables on that join) how do you know which join is need to be used? The select statement I have is: SELECT gc_skill_type.skill_type, gc_area_tec.area, gc_technology.technology, gc_technology.id_technology, gc_area_tec.id_area_tec FROM gc_skill_type, gc_area_tec, gc_technology WHERE gc_area_tec.id_skill_type (+) = gc_skill_type.id_skill_type AND gc_technology.id_area_tec (+) = gc_area_tec.id_area_tec order by gc_skill_type.skill_type asc, gc_area_tec.area asc, gc_technology.technology asc

3243


Explain aggregate functions are available there in sql?

534


What is lexical units in pl sql?

575


What is dense_rank?

540






Why cannot I use bind variables in ddl/scl statements in dynamic sql?

669


What is a primary key sql?

565


What is integrity in sql?

562


What is the difference between alter trigger and drop trigger statements?

602


Which data type is a composite type?

534


What is a boolean in sql?

526


Is it possible to create startup or shutdown trigger for on-schema?

587


what are all types of user defined functions? : Sql dba

550


which types of join is used in sql widely? : Sql dba

542


What are expressions?

564