Check out example codes for "sql join on a subquery". It will help you in understanding the concepts better.

Code Example 1

SELECT * 
FROM
( SELECT ... FROM ... ) q1

INNER JOIN

( SELECT ... FROM ... ) q2

ON q1.colname = q2.colname

Learn ReactJs, React Native from akashmittal.com