Returns distinct values by comparing the results of two queries.
EXCEPT returns any distinct values from the left query that are not also found on the right query. |
CREATE TABLE EmployeeInfo (EmpNo INT NOT NULL, EmpName VARCHAR(10), EmpPost VARCHAR(100), ManagerID INT, Salery INT, COMM INT, DeptNO INT); INSERT INTO EmployeeInfo VALUES (7369, 'Test1', 'PM', 7902, 800, NULL, 20); INSERT INTO EmployeeInfo VALUES (7499, 'Test2', 'PM', 7698, 1600, 300, 30); INSERT INTO EmployeeInfo VALUES (7521, 'Test3', 'SPM', 7698, 1250, 500, 30); INSERT INTO EmployeeInfo VALUES (7566, 'Test4', 'SPM', 7839, 2975, NULL, 20); INSERT INTO EmployeeInfo VALUES (7654, 'Test5', 'TeamLeader', 7698, 1250, 1400, 30); INSERT INTO EmployeeInfo VALUES (7698, 'Test6', 'TeamLeader', 7839, 2850, NULL, 30); INSERT INTO EmployeeInfo VALUES (7782, 'Test7', 'Project Lead', 7839, 2450, NULL, 10); INSERT INTO EmployeeInfo VALUES (7788, 'Test8', 'Project Lead', 7566, 3000, NULL, 20); INSERT INTO EmployeeInfo VALUES (7839, 'Test9', 'Architect', NULL, 5000, NULL, 10); INSERT INTO EmployeeInfo VALUES (7844, 'Test10', 'Architect', 7698, 1500, 0, 30); INSERT INTO EmployeeInfo VALUES (7876, 'Test11', 'Sr.SoftwareEngineer', 7788, 1100, NULL, 20); INSERT INTO EmployeeInfo VALUES (7900, 'Test12', 'Sr.SoftwareEngineer', 7698, 950, NULL, 30); INSERT INTO EmployeeInfo VALUES (7902, 'Test13', 'Sr.SoftwareEngineer', 7566, 3000, NULL, 20); INSERT INTO EmployeeInfo VALUES (7934, 'Test14', 'Sr.SoftwareEngineer', 7782, 1300, NULL, 10); SELECT * FROM EmployeeInfo; SELECT EmpNo, EmpName FROM EmployeeInfo WHERE Salery > 1000 EXCEPT SELECT EmpNo, EmpName FROM EmployeeInfo WHERE Salery > 2000 Result is below:- |
No comments :
Post a Comment