Joining the same table to reference a value within that same table ...
parent_ _id
parent_category_id of 2, meaning that it has a parent category with the id=2Table: Categories
id | name | parent_category_id
------------------------------------
1 | | 2
2 | | 5
3 | | 2
4 | | 0
5 | | 1
SELECT p.name AS "Parent",
s.name AS "Category"
FROM Categories p
LEFT JOIN Categories s
ON s.category_parent_id = p.id
LEFT JOIN the same table (produces full result)c will reference the category_parent_id and c2 will reference the id columnJOIN by just using a
SELECT statementSELECT column_1,
( SELECT col_name FROM tble2 t2 WHERE t2.something_id = tble2.id ) #should return 1 record!
JOIN tble2 ON ..
FROM table