Wednesday, May 30, 2007

SQL Inner Join, Left Join and Right Join

Below is a Example for SQL inner join, SQL Left Join and SQL Right Join.

GuestIDName
1001Nick
1002Jack
1003Apple
Table A

ProductGuestID
Table1002
Chair1003
Almari1002

Table B

SQL inner join
Example for SQL inner join
- Join more than 1 table to get other table data
1. SELECT A.Name, B.Product FROM A INNER JOIN B ON A.GuestID=B.GuestID
Result :


NameProduct
JackTable
AppleChair
JackAlmari

2. SELECT A.Name, B.Product FROM A INNER JOIN B ON A.GuestID=B.GuestID WHERE B.Product = 'tABLE'


Result:
NameProduct
JackTable