I have this query and it works great (not sure) about performance
SELECT ssp.product_id, p.price
FROM system_step_product AS ssp
JOIN product AS p ON p.product_id=ssp.product_id
WHERE ssp.system_id = 14
AND ssp.step_number = (
SELECT step_number
FROM system_step_product
WHERE system_id = '14'
AND step_number > (
SELECT step_number
FROM system_step_product
WHERE system_id = '14'
AND product_id = '81'
ORDER BY step_number ASC
LIMIT 1
)
ORDER BY step_number ASC
LIMIT 1
)
If I have to go about it with this approach I will but i was wondering if anyone can think of a better way of executing this query
The two limit clauses make the join statement require the
row_number() OVER ()window function, which is not available in MySQL. And even that, would likely make your query less efficient than it currently is.