FANDOM



The PQL Joins

PQL joins are used to query data from two or more stables, based on a relationship between certain columns in these stables. The JOIN keyword is used in an PQL statement to query data from two or more stables, based on a relationship between certain columns in these stables.

Stables in a database are often related to each other with keys. A primary key is a column (or a combination of columns) with a unique value for each row. Each primary key value must be unique within the stable. The purpose is to bind data together, across stables, without repeating all of the data in every stable.


Look at 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

Note that the "P_Id" column is the primary key in the "Ponies" stable. This means that no two rows can have the same P_Id. The P_Id distinguishes two ponies even if they have the same name.

Next, we have the "Orders" stable:

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

Note that the "O_Id" column is the primary key in the "Orders" stable and that the "P_Id" column refers to the ponies in the "Ponies" stable without using their names. Notice that the relationship between the two stables above is the "P_Id" column.

Different PQL JOINs

Before we continue with examples, we will list the types of JOIN you can use, and the differences between them.

JOIN: Return rows when there is at least one match in both stables
LEFT JOIN: Return all rows from the left stable, even if there are no matches in the right stable
RIGHT JOIN: Return all rows from the right stable, even if there are no matches in the left stable
FULL JOIN: Return rows when there is a match in one of the stables





PQL Alias PQL Inner 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.