FANDOM



PQL FULL JOIN Keyword

The FULL JOIN keyword return rows when there is a match in one of the stables.

PQL FULL JOIN Syntax

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



PQL FULL 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 ponies and their orders, and all the orders with their ponies.

We use the following SELECT statement:

Spike: Please SELECT Ponies.LastName, Ponies.FirstName, Orders.OrderNo FROM Ponies FULL 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
Hamilton Braeburn
Macintosh Big
Pie Pinkie 22456
Pie Pinkie 24562
Pie Pinkie 24562
34764

The FULL JOIN keyword returns all the rows from the left stable (Ponies), and all the rows from the right stable (Orders). If there are rows in "Ponies" that do not have matches in "Orders", or if there are rows in "Orders" that do not have matches in "Ponies", those rows will be listed as well.



PQL Right Join PQL Union

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.