SQL Server - Inner join - Asked By meimei on 31-Mar-12 10:01 AM

please give me sample of query for 3 kinds of table using inner join..
thanks..
Web Star replied to meimei on 31-Mar-12 12:14 PM
What do you mean by 3 kind of table? If you want to join three table using INNER JOIN than simply one thing required that any one column should be common between two table than you can use simply Inner Join as folllows

Select t1.*, t2.*, t3.*  From tablename1 t1 INNER JOIN tablename2 t2 ON t1.Sno = t2.Sno
          INNER JOIN tablename3 t3 ON t2.Id = t3.Id


You can join two table with other third if that one table hold the common column for both table.

hope this help you
kalpana aparnathi replied to meimei on 31-Mar-12 02:42 PM
hi,

Use below query:


SELECT * FROM tbl_name1 INNER JOIN (tbl_name1 INNER JOIN tbl_name2 ON tbl_name1.ID = tbl_name2.ID) ON tbl_name3.ID = tbl_name2.ID
Hope Will Helps!!!!!!!!!!!!!!!!!

Regards,
Devil Scorpio replied to meimei on 31-Mar-12 04:52 PM
Hi,

Here the exmple with image



SELECT O.OrderID,O.CustID,O.OrderTotal,C.Name, OC.OrderAmount
FROM Orders as O
INNER JOIN Customers as C
 
ON O.CustID=C.CustID
INNER JOIN OrderItems as OC
 
ON O.OrderID=OC.OrderID