To extend the answer to @Femi:
There is no good way to limit JOIN , and in fact, you really don't want to. Assuming that both products_image.product_id and products.id have indexes (and they must be, if you intend to join them again) when the database engine makes the connection, it uses indexes to determine which rows to retrieve. The engine then uses the results to determine where to find the records on the disc. If you
You can see the difference by running these SQL statements:
EXPLAIN SELECT p.product_id, p.product_name, i.img_name, i.img_ext FROM products p LEFT JOIN products_images i ON i.product_id = p.product_id
Unlike:
EXPLAIN SELECT p.product_id, p.product_name, i.img_name, i.img_ext FROM (SELECT product_id, product_name FROM products) p LEFT JOIN (SELECT img_name, img_ext FROM products_images) i ON i.product_id = p.product_id
The first request must have an index, the second - no. There should be a difference in performance if there is a significant number of rows in the database.
source share