One of the JR. Developer asked me a day ago, does SQL Server has similar operation like MINUS clause in Oracle.
Absolutely, EXCEPT clause in SQL Server is exactly similar to MINUS operation in Oracle. The EXCEPT query and MINUS query returns all rows in the first query that are not returned in the second query. Each SQL statement within the EXCEPT query and MINUS query must have the same number of fields in the result sets with similar data types.
Let us see that using example below. First create table in SQL Server and Oracle.
CREATE TABLE EmployeeRecord
(EmpNo INT NOT NULL, EmpName VARCHAR(10),
EmpPost VARCHAR(9), ManagerID INT,
Salery INT, COMM INT, DeptNO INT);
INSERT INTO EmployeeRecord
VALUES (7369, ‘SMITH’, ‘CLERK’, 7902, 800, NULL, 20);
INSERT INTO EmployeeRecord
VALUES (7499, ‘ALLEN’, ‘SALESMAN’, 7698, 1600, 300, 30);
INSERT INTO EmployeeRecord
VALUES (7521, ‘WARD’, ‘SALESMAN’, 7698, 1250, 500, 30);
INSERT INTO EmployeeRecord
VALUES (7566, ‘JONES’, ‘MANAGER’, 7839, 2975, NULL, 20);
INSERT INTO EmployeeRecord
VALUES (7654, ‘MARTIN’, ‘SALESMAN’, 7698, 1250, 1400, 30);
INSERT INTO EmployeeRecord
VALUES (7698, ‘BLAKE’, ‘MANAGER’, 7839, 2850, NULL, 30);
INSERT INTO EmployeeRecord
VALUES (7782, ‘CLARK’, ‘MANAGER’, 7839, 2450, NULL, 10);
INSERT INTO EmployeeRecord
VALUES (7788, ‘SCOTT’, ‘ANALYST’, 7566, 3000, NULL, 20);
INSERT INTO EmployeeRecord
VALUES (7839, ‘KING’, ‘PRESIDENT’, NULL, 5000, NULL, 10);
INSERT INTO EmployeeRecord
VALUES (7844, ‘TURNER’, ‘SALESMAN’, 7698, 1500, 0, 30);
INSERT INTO EmployeeRecord
VALUES (7876, ‘ADAMS’, ‘CLERK’, 7788, 1100, NULL, 20);
INSERT INTO EmployeeRecord
VALUES (7900, ‘JAMES’, ‘CLERK’, 7698, 950, NULL, 30);
INSERT INTO EmployeeRecord
VALUES (7902, ‘FORD’, ‘ANALYST’, 7566, 3000, NULL, 20);
INSERT INTO EmployeeRecord
VALUES (7934, ‘MILLER’, ‘CLERK’, 7782, 1300, NULL, 10);
SELECT *
FROM EmployeeRecord;
Now run following query in SQL Server:
SELECT EmpNo, EmpName
FROM EmployeeRecord
WHERE Salery > 1000
EXCEPT
SELECT EmpNo, EmpName
FROM EmployeeRecord
WHERE Salery > 2000
ORDER BY EmpName;
Now run following query in Oracle:
SELECT EmpNo, EmpName
FROM EmployeeRecord
WHERE Salery > 1000
MINUS
SELECT EmpNo, EmpName
FROM EmployeeRecord
WHERE Salery > 2000
ORDER BY EmpName;
You will find that both the query will return you same results.

Drop the table in SQL Server and Oracle as we are done with example.
DROP TABLE EmployeeRecord;
This proves that EXCEPT clause in SQL Server is same as MINUS clause in Oracle.
Reference : Pinal Dave (http://www.SQLAuthority.com)






Pinal,
What are your recommendations for when to use EXCEPT, NOT EXISTS, and NOT IN? They all seem to provide similar functionality.
Thanks,
Dan
Hello, sql authority — I have a puzzle for you…I wrote the following code:
select id
from records
EXCEPT
select id
from records
where cols = -1
WHICH RETURNS THIS ERROR MESSAGE:
Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword ‘EXCEPT’.
I’m using Microsoft sql server management studio express — the same as in the example you have above. Do you see anything wrong with this query as it appears above? I can’t! I had “distinct” in the select statements, but took them out, because the documentation I found online says that it works on distinct rows within the except function.
Help!
Donna Bursey
Hmm, strange statement. I have the same question in my mind as Dan above.
@Dan, @elfy,
From my experience I would use EXCEPT, NOT EXISTS and NOT IN in the order they are mentioned. EXCEPT (Best performance) and NOT IN (Worst performance).
Kind Regards,
Pinal Dave
I was really happy to find INTERSECT & EXCEPT in SQL 2005, similiar to Oracle’s MINUS is quite cool
Although I think I’ve tried it, I think
NOT EXISTS >> EXCEPT (does it not Cartesian than filter?) >> NOT IN (bad bad bad)
It could also depend on the data sets, but I’ve recommended everyone I know to code with NOT EXISTS in mind
this worked like a charm!
much, much faster than NOT IN…
regards,
Giovanna
SIR
i have creataed a table in which i have inserted different students marks
now i want to write a program(may be it is done through function or procedure) in oracle sql so that user is prompted to enter the top values i mean if user want to access top 10 students marks so he just need to write 10 in the box and result should be displayed similarly for top 15 in short from top 1- top 15
just like if i write the quuery
select * from stu where stu_marks=’&Entertop’
so user is prompted to enter top values but i want to write a program for it in oracle sql(pl sql)
i shall be thankful to you