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

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> SQL Query >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Inner join in SQL

Posted By:Ashutosh Jha       Posted Date: June 30, 2014    Points: 40    Category: SQL Query    URL: http://www.dotnetspark.com  

How to use inner join and intersect in SQL Server

Declare @a_table1 table (Id int, firstName varchar(50))
Declare @a_table2 table (Id int, firstName varchar(50))
--Insert some records
Insert into @a_table1 values (1,NULL)
Insert into @a_table2 values (1,NULL)
-- Inner Join-example
Select t1.*
from @a_table1 t1
inner join @a_table2 t2
t1.Id=t2.Id and t1.firstName=t2.firstName
-- INTERSECT-example
Select * from @a_table1
Select * from @a_table2

Run and result will be-

  Inner Join -- No data displays.
 INTERSECT -- Row displays.


Further Readings:


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