UserID
|
UserName
|
FirstName
|
LastName
|
1
|
SureshDasari
|
Suresh
|
Dasari
|
2
|
PrasanthiDonthi
|
Prasanthi
|
Donthi
|
3
|
MaheshDasari
|
Mahesh
|
Dasari
|
OrderID
|
OrderNo
|
UserID
|
1
|
543224
|
1
|
2
|
213424
|
2
|
3
|
977776
|
3
|
4
|
323233
|
3
|
5
|
998756
|
1
|
SELECT t1.column_name,t2.column_name
FROM table_name1 t1
INNER JOIN table_name2 t2
ON t1.column_name=t2.column_name
|
SELECT u.UserName,u.LastName,o.OrderNo
FROM UserDetails u
INNER JOIN OrderDetails o
ON u.UserID=o.UserID
|
UserName
|
LastName
|
OrderNo
|
SureshDasari
|
Dasari
|
543224
|
PrasanthiDonthi
|
Donthi
|
213424
|
MaheshDasari
|
Dasari
|
977776
|
MaheshDasari
|
Dasari
|
323233
|
SureshDasari
|
Dasari
|
998756
|
SELECT u.UserName,u.LastName,o.OrderNo
FROM UserDetails u
JOIN OrderDetails o
ON u.UserID=o.UserID
|
SELECT * FROM table_name1 t1
INNER JOIN table_name2 t2
ON t1.column_name=t2.column_name
|
SELECT *
FROM UserDetails u
INNER JOIN OrderDetails o
ON u.UserID=o.UserID
|
UserID
|
UserName
|
FirstName
|
LastName
|
OrderID
|
OrderNo
|
UserID
|
1
|
SureshDasari
|
Suresh
|
Dasari
|
1
|
543224
|
1
|
2
|
PrasanthiDonthi
|
Prasanthi
|
Donthi
|
2
|
213424
|
2
|
3
|
MaheshDasari
|
Mahesh
|
Dasari
|
3
|
977776
|
3
|
3
|
MaheshDasari
|
Mahesh
|
Dasari
|
4
|
323233
|
3
|
1
|
SureshDasari
|
Suresh
|
Dasari
|
5
|
998756
|
1
|
SELECT * FROM table_name1 t1
NATURAL JOIN table_name2 t2
|
SELECT *
FROM UserDetails
NATURAL JOIN OrderDetails
|
SELECT * FROM table_name1
CROSS JOIN table_name2
|
SELECT * FROM table_name1,table_name2
|
SELECT * FROM UserDetails
CROSS JOIN OrderDetails
|
SELECT * FROM UserDetails, OrderDetails
|
UserID
|
UserName
|
FirstName
|
LastName
|
OrderID
|
OrderNo
|
UserID
|
1
|
SureshDasari
|
Suresh
|
Dasari
|
1
|
543224
|
1
|
1
|
SureshDasari
|
Suresh
|
Dasari
|
2
|
213424
|
2
|
1
|
SureshDasari
|
Suresh
|
Dasari
|
3
|
977776
|
3
|
1
|
SureshDasari
|
Suresh
|
Dasari
|
4
|
323233
|
3
|
1
|
SureshDasari
|
Suresh
|
Dasari
|
5
|
998756
|
1
|
2
|
PrasanthiDonthi
|
Prasanthi
|
Donthi
|
1
|
543224
|
1
|
2
|
PrasanthiDonthi
|
Prasanthi
|
Donthi
|
2
|
213424
|
2
|
2
|
PrasanthiDonthi
|
Prasanthi
|
Donthi
|
3
|
977776
|
3
|
2
|
PrasanthiDonthi
|
Prasanthi
|
Donthi
|
4
|
323233
|
3
|
2
|
PrasanthiDonthi
|
Prasanthi
|
Donthi
|
5
|
998756
|
1
|
3
|
MaheshDasari
|
Mahesh
|
Dasari
|
1
|
543224
|
1
|
3
|
MaheshDasari
|
Mahesh
|
Dasari
|
2
|
213424
|
2
|
3
|
MaheshDasari
|
Mahesh
|
Dasari
|
3
|
977776
|
3
|
3
|
MaheshDasari
|
Mahesh
|
Dasari
|
4
|
323233
|
3
|
3
|
MaheshDasari
|
Mahesh
|
Dasari
|
5
|
998756
|
1
|
SELECT Column_List FROM table_name1 t1
LEFT OUTER JOIN table_name2 t2
ON t1.column_name=t2.column_name
|
SELECT u.UserID,u.UserName,o.OrderNo
FROM UserDetails u
LEFT OUTER JOIN OrderDetails o
ON u.UserID=o.UserID
|
UserID
|
UserName
|
OrderNo
|
1
|
SureshDasari
|
543224
|
1
|
SureshDasari
|
998756
|
2
|
PrasanthiDonthi
|
213424
|
3
|
MaheshDasari
|
977776
|
3
|
MaheshDasari
|
323233
|
SELECT Column_List FROM table_name1 t1
RIGHT OUTER JOIN table_name2 t2
ON t1.column_name=t2.column_name
|
SELECT u.UserID,u.UserName,o.OrderNo
FROM UserDetails u
RIGHT OUTER JOIN OrderDetails o
ON u.UserID=o.UserID
|
UserID
|
UserName
|
OrderNo
|
1
|
SureshDasari
|
543224
|
2
|
PrasanthiDonthi
|
213424
|
3
|
MaheshDasari
|
977776
|
3
|
MaheshDasari
|
323233
|
1
|
SureshDasari
|
998756
|
SELECT Column_List FROM table_name1 t1
FULL OUTER JOIN table_name2 t2
ON t1.column_name=t2.column_name
|
SELECT u.UserID,u.UserName,o.OrderNo
FROM UserDetails u
FULL OUTER JOIN OrderDetails o
ON u.UserID=o.UserID
|
UserID
|
UserName
|
FirstName
|
LastName
|
OrderID
|
OrderNo
|
UserID
|
1
|
SureshDasari
|
Suresh
|
Dasari
|
1
|
543224
|
1
|
1
|
SureshDasari
|
Suresh
|
Dasari
|
5
|
998756
|
1
|
2
|
PrasanthiDonthi
|
Prasanthi
|
Donthi
|
2
|
213424
|
2
|
3
|
MaheshDasari
|
Mahesh
|
Dasari
|
3
|
977776
|
3
|
3
|
MaheshDasari
|
Mahesh
|
Dasari
|
4
|
323233
|
3
|
EmpID
|
EmpName
|
EmpMgrID
|
1
|
Suresh
|
2
|
2
|
Prasanthi
|
4
|
3
|
Mahesh
|
2
|
4
|
Sai
|
1
|
5
|
Nagaraju
|
1
|
6
|
Mahendra
|
3
|
7
|
Sanjay
|
3
|
select e2.EmpName,e1.EmpName as 'Manager'
from EmployeeDetails e1
INNER JOIN EmployeeDetails e2
on e1.EmpID=e2.EmpMgrID
|
EmpName
|
Manger
|
Sai
|
Suresh
|
Nagaraju
|
Suresh
|
Suresh
|
Prasanthi
|
Mahesh
|
Prasanthi
|
Mahendra
|
Mahesh
|
Sanjay
|
Mahesh
|
Prasanthi
|
Sai
|
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
Subscribe by RSS
Subscribe by Email
|
|||
|
|
|
Subscribe by RSS
Subscribe by Email
38 comments :
Dear Suresh,
I had three table
1. tEmployeeInfo(EmpID, EmpName, )
2. tEmployeeList(EmpID, RoleID)
3. tServiseCustMapping(RoleID)
In tServiseCustMapping, thr are three column
tblID, SERProviderRoleID, CUSRoleId
which display the relation that which RoleID is ServiceProvider of which Customer(Both Service Prov. and Cutomer is represent by Role ID)
and tEmployeeInfo shows the which employeeID is has which RoleID.
And last tEmployeeList has EmployeeName and all Employee INfo.
A RoleID can hav Multiple EmployeeID but One EmployeeID can have one RoleID.
If a ServProv RoleID has Two Employee and Customer RoleID has Three EmployeeID.
Then I Need To show in GridView All Service Provider and Customer Relation with based On Employee based.
Please Help Me.
Thanks
Shamim Ansari
hey very nice articles!!!
can you post a article describing all the types of user defined function,scaler function of SQL
GREAT EXPLANATION.........
I clear join concept from here .....
good
very good
hi sir,
i have id,name in one table,if i select name i shoud get name of the id.give me a solution for tis
UUO
good
how to calculate cummulative target,sales and runrate based on cummulative target and sales
on single table with financial year from 2012-13 to 2014-14(example) and weeks colum 1-52 for pericular year
k
nice
Hi Suresh,
It seems good with explanation.
Great
Thanks,
good
good
Hi suresh, its nice to read ur article but it will be very useful and understandable if u provide the different outputs for different joins .
I am not getting the actual idea of what u have given the above example of inner joins and outer joins
so, can u plz keep the modified article?
yaa mate awesome perfect explanation like people understanding their own handwriting in there books than sumone else ... loud and clear
Very clear explanation...helps a lot
gud
Very nice article with clear explanation ...Thank you!!!
thnks.......
gud,but some more examples pls
niceeeeeee..........
nice
Really a good explanation of joins very clearer
very good
good article
it really helpd me lot :) thanks
its very use full ....
Dear Suresh,
I am one of regular readers of your blog. Today when I was reading your article about the Joins (http://www.aspdotnet-suresh.com/2011/12/different-types-of-joins-in-sql-server.html) I noticed that in the explanation of Full Outer Join you have given correct syntax but in the example there is mistake .
Your syntax is:
SELECT Column_List FROM table_name1 t1
FULL OUTER JOIN table_name2 t2
ON t1.column_name=t2.column_name
and Example is:
SELECT u.UserID,u.UserName,o.OrderNo
FROM UserDetails u
RIGHT OUTER JOIN OrderDetails o
ON u.UserID=o.UserID
so instead of using Full Outer Join you have specified Right Outer Join.
Please correct the above mentioned mistake.
Thanks & Regards:
Manish Kumar
@Manish...
Thanks. i updated the post....
Hi Suresh,
It seems good with explanation.
Great
Thanks,
Thank you...
Very Gud article...
Dear Sir,
I have lot of Doubts in Number series formats with auto increment,please help me the above.
Thanks and Regards,
Jayakumar
verry good
HHH
Great...
Thanks.
HOW TO CALL IT FROM .CS PAGE OR .ASPX PAGE IS A QUESTION FOR THE FRESHERS LIKE ME,
OTHERWISE THIS ARTICLE IS AS GREAT LIKE YOU SIR,
HAT'S OFF TO YOU