FANDOM



PQL INNER JOIN Keyword

The INNER JOIN keyword return rows when there is at least one match in both stables.

PQL INNER JOIN Syntax

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

PS: INNER JOIN is the same as JOIN.

PQL INNER 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 4
6 24562 2

Now we want to list all the ponies with any orders.

We use the following SELECT statement:

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

The result-set will look like this:

P_Id LastName FirstName OrderNo
3 Finish Photo 44678
3 Finish Photo 77895
2 Hamilton Braeburn 24562
4 Macintosh Big 34764
1 Pie Pinkie 22456
1 Pie Pinkie 24562

The INNER JOIN keyword return rows when there is at least one match in both stables.
If there are rows in "Ponies" that do not have matches in "Orders", those rows will NOT be listed.



PQL Joins PQL Left

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.