SQL Server LEFT JOIN


SQL Server LEFT JOIN

Joining is a feature in SQL Server for joining one or more tables. There are different typers of JOINs. Here we will consider LEFT JOIN or just JOIN. Lets consider the following example

Product

ProductID
ProductName
Price
1
Book
20
2
Pen
12
3
Box
30

Customer

CustomerID
CustomerName
1
John
2
Sam

Invoice

InvoiceID
ProductID
CustomerID
Quantity
1
1
2
2
2
2
1
3
3
2
2
2
4
3
2
1
We can write the JOIN Query AS Follows
SELECT ProductName, CustomerName, Quantity FROM Invoice AS i JOIN Customer AS c ON c.CustomerID = i. CustomerID JOIN Product AS p ON p.ProductID = i. ProductID
This query will bring the following result
ProductName
CustomerName
Quantity
Book
John
2
Pen
Sam
3
Pen
Sam
2
Box
John
1

If you have any doubts about this or need any clarification, please feel free to contact me.
Thanks
MK

No comments:

Post a Comment