| sample_ID |
sampleName |
sampleDate |
material_id |
sampleNote |
location_id |
| 1 |
blupilist |
2025-11-11 |
5 |
sculpture |
1 |
| 2 |
povsolfo |
2024-10-31 |
3 |
unknown |
2 |
| 3 |
syntaksipolontian |
1997-09-15 |
1 |
large |
3 |
| 4 |
bleas |
1983-01-01 |
2 |
heavy |
4 |
| 5 |
galpicgraitcaf |
1942-02-01 |
2 |
animate |
5 |
| 6 |
ivanseal |
1973-05-22 |
0 |
sculptor |
6 |
| 7 |
lelanki |
1974-05-09 |
0 |
multicomposite |
3 |
| material_ID |
materialName |
| 1 |
glass |
| 2 |
metal |
| 3 |
marble |
| 4 |
wood |
| 5 |
clay |
| 6 |
carbon fiber |
| location_ID |
locationName |
| 1 |
Alaska |
| 2 |
Alberta |
| 3 |
Sweden |
| 4 |
Yorkshire |
| 5 |
Siberia |
| 6 |
Cuba |
These three tables are the tables I used for my joins.
They are created by running dbfCreate.php. We have a table called sampleData, and a table called sampleMaterial.
If you are curious about the names in sampleData, they are derived from the works of Ivan Seal, an English abstract artist.
As you can see, sampleData has a record without material, 'ivanseal'. sampleMaterial has a material that is never used, wood.
SELECT * FROM sampleData d LEFT OUTER JOIN sampleMaterial m ON d.material_id = m.material_ID;
| sample_ID |
sampleName |
sampleDate |
material_id |
sampleNote |
location_id |
material_ID |
materialName |
| 1 |
blupilist |
2025-11-11 |
5 |
sculpture |
1 |
5 |
clay |
| 2 |
povsolfo |
2024-10-31 |
3 |
unknown |
2 |
3 |
marble |
| 3 |
syntaksipolontian |
1997-09-15 |
1 |
large |
3 |
1 |
glass |
| 4 |
bleas |
1983-01-01 |
2 |
heavy |
4 |
2 |
metal |
| 5 |
galpicgraitcaf |
1942-02-01 |
2 |
animate |
5 |
2 |
metal |
| 6 |
ivanseal |
1973-05-22 |
0 |
sculptor |
6 |
|
|
| 7 |
lelanki |
1974-05-09 |
0 |
multicomposite |
3 |
|
|
SELECT * FROM sampleData d RIGHT OUTER JOIN sampleMaterial m ON d.material_id = m.material_ID;
| sample_ID |
sampleName |
sampleDate |
material_id |
sampleNote |
location_id |
material_ID |
materialName |
| 1 |
blupilist |
2025-11-11 |
5 |
sculpture |
1 |
5 |
clay |
| 2 |
povsolfo |
2024-10-31 |
3 |
unknown |
2 |
3 |
marble |
| 3 |
syntaksipolontian |
1997-09-15 |
1 |
large |
3 |
1 |
glass |
| 4 |
bleas |
1983-01-01 |
2 |
heavy |
4 |
2 |
metal |
| 5 |
galpicgraitcaf |
1942-02-01 |
2 |
animate |
5 |
2 |
metal |
|
|
|
|
|
|
4 |
wood |
|
|
|
|
|
|
6 |
carbon fiber |
Data from all tables combined.
| sample_ID |
sampleName |
sampleDate |
material_id |
sampleNote |
location_id |
material_ID |
materialName |
location_ID |
locationName |
| 1 |
blupilist |
2025-11-11 |
5 |
sculpture |
1 |
5 |
clay |
1 |
Alaska |
| 2 |
povsolfo |
2024-10-31 |
3 |
unknown |
2 |
3 |
marble |
2 |
Alberta |
| 3 |
syntaksipolontian |
1997-09-15 |
1 |
large |
3 |
1 |
glass |
3 |
Sweden |
| 4 |
bleas |
1983-01-01 |
2 |
heavy |
4 |
2 |
metal |
4 |
Yorkshire |
| 5 |
galpicgraitcaf |
1942-02-01 |
2 |
animate |
5 |
2 |
metal |
5 |
Siberia |
As you can see, a RIGHT OUTER JOIN and a LEFT OUTER JOIN produce different results. Why is that? When joining two tables in SQL, the first table added is the left table. The second table is the right. A LEFT OUTER JOIN query keeps everything in the left table, and anything that matches it from the right table. You can see this in the LEFT OUTER JOIN example, as the sample 'ivanseal' is kept without a material, but 'wood' is discarded as no samples have 'wood' as their material.
A RIGHT OUTER JOIN does the opposite. It keeps everything from the right table, and discards things in the left that don't match a record in it. Because 'ivanseal' doesn't have a material, it is removed. However, 'wood' is now in the table despite nothing in sampleData being made of wood.
Finally, an inner join returns all records that match the condition set. In this case, ones that have both a location (which they all have) and a material. Entries that don't match that condition are discarded.