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:
|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:
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|