What is use of EXCEPT Clause?

          

Interview questions

SQL Server - What is use of EXCEPT Clause?

Next>>         SQL Server tutorial  

SQL Server - What is use of EXCEPT Clause? - Feb 27, 2010 at 11:50 AM by Shuchi Gauri

What is use of EXCEPT Clause? Explain with an example

EXCEPT clause returns any distinct values from the left query that are not found in the right side query.

Eg:

USE AdventureWorks;
GO
SELECT ProductID
FROM Production.Product
EXCEPT
SELECT ProductID
FROM Production.WorkOrder ;

SQL Server - What is use of EXCEPT Clause? - May 05, 2009 at 22:00 PM by Rajmeet Ghai

What is use of EXCEPT Clause? Explain with an example

EXCEPT clause is used to return records that are returned by the first query and NOT the second query. The number of fields and data types of both the queries should be the same.

Example:

SELECT Empid, EmpName FROM Employee WHERE Salary > 1000 EXCEPT SELECT Empid, EmpName FROM Employee WHERE Salary > 1500

SQL Server - What is use of EXCEPT Clause? - June 21, 2009 at 09:00 AM by Amit Satpute

To filter the result of a query to suit a certain criteria, the NOT IN clause can be used as follows:

Data of emp table;

EMPNO           ENAME               TITLE
-----------          ----------               --------
2                      SMITH                 CLERK
1                      ALLEN                SALESMAN
3                      WARD                 CLERK    
4                      JONES                SALESMAN
5                      MARTIN               CLERK

select * from emp where 2 not in empno;

OUTPUT:

1                      ALLEN                 SALESMAN   
3                      WARD                  CLERK
4                     JONES                  SALESMAN
5                     MARTIN                 CLERK


Next>>

Also read

Define Truncate and Delete commands.

Answer - Truncate command is used to remove all rows of the column.The removed records are not recorded in the transaction log......

Define Identity and uniqueidentifier property of Column.

Answer - Column with identity property contains unique system generated value in the table. Column with identity property is similar to AutoNumber field in MS Access....

Describe in brief SQL Server monitoring ways.

Answer - SQL Profiler is a tool that stores events from the server. SQL Profiler saves the events in the trace file......



Write your comment - Share Knowledge and Experience


 

 
Latest placement tests
Latest links
 
Latest MCQs
» General awareness - Banking » ASP.NET » PL/SQL » Mechanical Engineering
» IAS Prelims GS » Java » Programming Language » Electrical Engineering
» English » C++ » Software Engineering » Electronic Engineering
» Quantitative Aptitude » Oracle » English » Finance
Home | About us | Sitemap | Contact us | We are hiring