Consider this MySQL table:
Table 1
For MySQL versions that do not support Common Table Expressions (up to version 5.7), you could achieve this with the following query:
select id,
username,
sponser_id
from (select * from db_users
order by sponser_id, id) products_sorted,
(select @pv := '5') initialisation
where find_in_set(sponser_id, @pv)
and length(@pv := concat(@pv, ',', id));
I want to modify this query to perform inner join operations with another table.
Table 2 For table 2 you can take any example: