What is different between union and minus?

Answers were Sorted based on User's Feedback



What is different between union and minus?..

Answer / rahul gaikwad

Let's consider the difference between Minus and Union using
following examples.

1.create TABLE A AND B With similar structure
2.insert records in Table A and B.
3.Keep some records identical(here 2 rows).
4.find out the difference betwn 2 looking into the output.


CREATE TABLE A(NAME VARCHAR2(30));
INSERT INTO A VALUES('A');
INSERT INTO A VALUES('B');
INSERT INTO A VALUES('C');
INSERT INTO A VALUES('D');
COMMIT;

CREATE TABLE B(NAME VARCHAR2(30));
INSERT INTO b VALUES('A')
INSERT INTO b VALUES('B')
INSERT INTO b VALUES('Y')
INSERT INTO b VALUES('X')
COMMIT;



1) SELECT * FROM A
MINUS
SELECT * FROM B

NAME
------------------------------
C
D
2 rows selected



2)SELECT * FROM A
UNION
SELECT * FROM B


NAME
------------------------------
A
B
C
D
Y
x
6 rows selected

Is This Answer Correct ?    28 Yes 3 No

What is different between union and minus?..

Answer / humayun quaiser


unoin:- This operator returns from all the queries(combined
through union) but not duplicate record will be display.
ex- A={1,2,3,4}
B={2,3,4,5}
AUB={1,2,3,4,5}............

Minus:- This operator displays records which belongs to only
the first query.
ex:- A={1,2,3,4}
B= {2,3,5}
A-B={1,4}...................

Is This Answer Correct ?    24 Yes 0 No

What is different between union and minus?..

Answer / varma

union:
Union combines result set of two select statements
into one result set and from the result it eliminates
duplicate rows.

Minus:
Minus takes the result set of one select statement
and removes those rows that are also returned by another
select statement.

Is This Answer Correct ?    6 Yes 0 No

What is different between union and minus?..

Answer / bhaskar

UNION : Union combines the two table records, its eliminates
the duplicate records

Minus: ???

Is This Answer Correct ?    3 Yes 0 No

What is different between union and minus?..

Answer / pravin

Union combines the two table records, its eliminates
the duplicate records. while minus shows only those rows
which are not dulicated of table first in query.

Is This Answer Correct ?    3 Yes 1 No

What is different between union and minus?..

Answer / ajinkyasingh bais

The SQL UNION clause/operator is used to combine the results of two or more SELECT statements without any duplicate rows.
whereas
The SQL MINUS clause/operator is used to combine two SELECT statements,but returns rows only from the first SELECT statement that are identical to a row in the second SELECT statement

Is This Answer Correct ?    3 Yes 3 No

What is different between union and minus?..

Answer / 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

More SQL PLSQL Interview Questions

How is pl sql different from sql?

0 Answers  


Show the two pl/sql cursor exceptions.

0 Answers  


What is difference between primary and secondary key?

0 Answers  


What mean sql?

0 Answers  


What are the types of records?

0 Answers  






what is check constraint? : Sql dba

1 Answers  


select * from emp where sal in(select max(sal) from emp) here there is any limit for in operator how many values accpect ?

2 Answers  


what is a trigger in mysql? : Sql dba

0 Answers  


Can we use ddl statements in stored procedure sql server?

0 Answers  


how can you create an empty table from an existing table? : Sql dba

0 Answers  


what are the differences among these table level lock modes - IN SHARE MODE, IN SHARE UPDATE MODE, IN EXCLUSIVE MODE ?

3 Answers   HCL,


I need to write a simple query,which one is better select statement or stored procedure?and why?

2 Answers   iGate,


Categories