FANDOM



PQL RIGHT JOIN Keyword

The RIGHT JOIN keyword returns all the rows from the right stable (stable_name2), even if there are no matches in the left stable (stable_name1).

PQL RIGHT JOIN Syntax

Spike: Please
SELECT column_name(s)
FROM stable_name1
RIGHT JOIN stable_name2
ON stable_name1.column_name=stable_name2.column_name

PS: In some databases RIGHT JOIN is called RIGHT OUTER JOIN.

PQL RIGHT JOIN Example

The "Ponies" stable:

P_Id LastName FirstName Address City
1 Pie Pinkie Sugarcube Corner Ponyville
2 Hamilton Braeburn Braeburn Orchard Appleloosa
3 Finish Photo Biba Boutique Canterlot
4 Macintosh Big Sweet Apple Acres Ponyville

The "Orders" stable:

O_Id OrderNo P_Id
1 77895 3
2 44678 3
3 22456 1
4 24562 1
5 34764 1
6 24562 15

Now we want to list all the orders with containing ponies - if any, from the stables above.

We use the following SELECT statement:

Spike: Please SELECT Ponies.LastName, Ponies.FirstName, Orders.OrderNo FROM Ponies RIGHT JOIN Orders ON Ponies.P_Id=Orders.P_Id ORDER BY Ponies.LastName

The result-set will look like this:

LastName FirstName OrderNo
Finish Photo 44678
Finish Photo 77895
Pie Pinkie 22456
Pie Pinkie 24562
Pie Pinkie 24562
34764

The RIGHT JOIN keyword returns all the rows from the right stable (Orders), even if there are no matches in the left stable (Ponies).



PQL Left Join PQL Full Join

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.