.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
abhays
Clintonzz
arronlee
cathyhill345
mattyclown

Home >> Code Snippets >> Javascript >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Using EXCEPT and INTERSECT to compare tables in Sql Server

Posted By:Deco       Posted Date: September 22, 2010    Points: 5    Category: Javascript    URL: http://kilakarai-bites.blogspot.in  

Use of EXCEPT and INTERSECT in Sql Server
 

Except in Sql Server is used to return all the rows available in Table1 but not available in Table2
[code]
Table1

EmpName   Salary
--------------------
Alwyn          2000
Joe Durai     3000
Asbas          4000
 
Table2

EmpName    Salary
---------------------
Davood       1000
King             2000
Alwyn          2000
[/code]

We can use the Except in Sql Server like;

[code]
SELECT *
FROM Table1
EXCEPT
SELECT *
FROM Table2
[/code]

The result set will be like

[code]
EmpName   Salary
--------------------
Joe Durai     3000
Asbas          4000
[/code]


INTERSECT in Sql Server will return the rows that are available in both Table1 and Table 2

We can use INTERSECT like;

[code]
SELECT *
FROM Table1
INTERSECT
SELECT *
FROM Table2
[/code]


The Result  set will be lile;

[code]
EmpName   Salary
--------------------
Alwyn          2000
[/code]



     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend