Home > DeveloperSection > Forums > Use Intersect in sql server
Ankit Singh

Total Post:341

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

 Database SQL Server  SQL 
Ratings:


 1 Reply(s)
 237  View(s)
Rate this:
We want to use Intersect in sql server.how will do this please help me.


aditya kumar Patel

Total Post:242

Points:1722
Posted on    March-08-2016 10:20 PM

Intersect: The intersect statement is used to fetch the common records between the tables. Here we have two tables. Both tables have similar kinds of records.

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:

 

INTERSECT QUERY :

 

SELECT ProductId,ProductName,ManufacturedBy FROM ProductStock

INTERSECT

SELECT ProductId,ProductName,ManufacturedBy FROM ProductOrder

Result :

 


Modified On Mar-08-2016 10:31:15 PM

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

Follow MindStick