I have 2 tables.
workers and experience
In table workers there is row worker_parent (because one worker can be responsible for other).
No I must connect tables like that:
SELECT w1.* FROM workers w1 LEFT JOIN workers w2 ON (w2.id = w1.worker_parent)
And that’s ok. But I have to order by experience of w2 and I try to add table experience but it’s connect to w1 and not to w2.
My question is how to add table experience (which has row worker_id) to w2 and order by experience AND SELECT data from w1.
This is my try.
SELECT w1.* FROM workers w1 LEFT JOIN workers w2 ON (w2.id = w1.worker_parent) LEFT JOIN experience e ON (w2.id = e.worker_id) ORDER BY e.experience DESC
Thank’s for help
if you only want child workers that have a parent with experince,
you need to add a where (or change join type)
(for readability i renamed w1 and w2 to w_child and w_parent)