Home > DeveloperSection > Forums > How to use Except in Sql server
Ankit Singh

Total Post:341

Points:2389
Posted on    March-08-2016 10:13 PM

 Database SQL Server  SQL 
Ratings:


 1 Reply(s)
 249  View(s)
Rate this:
We want to use  Except in Sql server.how to use this please help me.


aditya kumar Patel

Total Post:246

Points:1752
Posted on    March-08-2016 10:27 PM

 

EXCEPT: The EXCEPT operator returns all distinct the rows that are present in the result set of the first query, but not in the result set of the second query. It means it returns the difference between the two result sets.

CREATE TABLE ProductStock

(

ProductId INT PRIMARY KEY IDENTITY(1,1),

ProductName VARCHAR(100),

ManufacturedBy VARCHAR(100),

StockQty BIGINT,

LastUpdated date

)

Go

CREATE TABLE ProductOrder

(

OrderId INT PRIMARY KEY IDENTITY(1,1),

ProductId int,

ProductName VARCHAR(100),

ManufacturedBy VARCHAR(100),

OrderQty BIGINT,

OrderDate date

)

 

ProductStock:

 

 

ProductOrder:

 

 

EXCEPT QUERY:

 

SELECT ProductId,ProductName,ManufacturedBy FROM ProductStock

EXCEPT

SELECT ProductId,ProductName,ManufacturedBy FROM ProductOrder

Result :


Don't want to miss updates? Please click the below button!

Follow MindStick