Example:

mysql> select * from tableA;
+-------+------+
| name  | age  |
+-------+------+
| Amit  | 27   |
| Sumit | 31   |
| Anand | 29   |
| Parry | 32   |
+-------+------+


mysql> select * from tableB;
+-------+--------+
| name  | Salary |
+-------+--------+
| Amit  | 50000  |
| Sumit | 60000  |
| Anand | 55000  |
| Alex  | 10000  |
| Ben   | 90000  |
+-------+--------+

TABLEA RIGHT JOIN TABLEB
mysql> Select tableA.Name, tableA.Age, tableB.Salary from tableA right join
tableB on tableA.Name=tableB.Name;
+-------+------+--------+
| Name  | Age  | Salary |
+-------+------+--------+
| Amit  | 27   | 50000  |
| Sumit | 31   | 60000  |
| Anand | 29   | 55000  |
| NULL  | NULL | 10000  |
| NULL  | NULL | 90000  |
+-------+------+--------+


TABLEA LEFT JOIN TABLEB
mysql> Select tableA.Name, tableA.Age, tableB.Salary from tableA left join
tableB on tableA.Name=tableB.Name;
+-------+------+--------+
| Name  | Age  | Salary |
+-------+------+--------+
| Amit  | 27   | 50000  |
| Sumit | 31   | 60000  |
| Anand | 29   | 55000  |
| Parry | 32   | NULL   |
+-------+------+--------+

Regards,
Amit Sharma @ Affle

-----Original Message-----
From: mos [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, July 22, 2008 7:59 PM
To: mysql@lists.mysql.com
Subject: Re: LEFT JOIN and RIGHT JOIN

At 09:05 AM 7/22/2008, you wrote:
>Hi All,
>Can u please let me know when should i use LEFT JOIN and when should i
going
>for a RIGHT JOIN. Please let me know some examples.
>
>regards
>anandkl

anandkl,

Take a look at the tutorial at 
http://www.keithjbrown.co.uk/vworks/mysql/mysql_p5.php

Mike 


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to