Leakbali
w3 Tutorial, Web Tutorial
Register   Login
Share

MySQL Right Join 


The RIGHT JOIN keyword returns all the rows from the right table (table_name2), even if there are no matches in the left table (table_name1).

MySQL RIGHT JOIN Syntax

SELECT column_name(s)
FROM table_name1
RIGHT JOIN table_name2
ON table_name1.column_name=table_name2.column_name

MySQL RIGHT JOIN Example

The "Persons" table: PutuMadeNyoman
P_IdFirstNameLastNameAddressCity
1SanjayaJl. Sudirman 20Denpasar
2SanjayaJl. Teuku Umar 22Denpasar
3SanjayaJl. Imam Bonjol 11Denpasar
The "Orders" table: >
O_IdOrderNoP_Id
1232383
2793823
3485921
4456452
5384584
Now we want to list all the orders with containing persons - if any, from the tables above. We use the following SELECT statement:
SELECT Persons.FirstName, Persons.LastName, Orders.OrderNo
FROM Persons
RIGHT JOIN Orders
ON Persons.P_Id=Orders.P_Id
ORDER BY Persons.LastName
The result-set will look like this:
FirstNameLastNameOrderNo
NyomanSanjaya23238
NyomanSanjaya23238
PutuSanjaya48592
MadeSanjaya45645
38458
The RIGHT JOIN keyword returns all the rows from the right table (Orders), even if there are no matches in the left table (Persons).
More Tutorial
  1. MYSQL - MySQL Right Join

References

About Us

Home
About Us
Contact Us
Sitemap

Tools

Google PageRank
Alexa Rank
Keywords Density

Accounts

Register Account
Login
Valid XHTML 1.0 TransitionalValid CSS!
Web Directory


2006 - 2012 © Leakbali.com - Free Web Tutorial, Free Web Articles, Web Sharing, Source Codes, Web References