Reputation: 433
How to match and product_id in the query atm the query is pull only missing result but each product have his own record and need to match with this record
This query work right but isn't match product_id
SELECT oc_ekstri_frontend.*,
oc_ekstri_image.id as img_id,
oc_ekstri_image.name
FROM oc_ekstri_image
LEFT JOIN oc_ekstri_frontend ON (oc_ekstri_frontend.id = oc_ekstri_image.frontend_id)
LEFT JOIN oc_ekstri_frontend_view ON (oc_ekstri_frontend_view.ekstri_id = oc_ekstri_image.id)
WHERE oc_ekstri_frontend.subcat_id = '" . $id . "'
AND oc_ekstri_frontend_view.ekstri_id IS NULL
How will I match for current product_id? I tried something like this to add to the query but isn't work result is empty
AND oc_ekstri_frontend_view.product_id = '" . $product_id . "'
Upvotes: 1
Views: 38
Reputation: 522626
Without seeing your data or your expected output, it is hard to give an exact answer. One possible solution might be to move your new restriction from the WHERE
clause to the ON
clause:
SELECT
f.*,
i.id AS img_id,
i.name
FROM oc_ekstri_image i
LEFT JOIN oc_ekstri_frontend f
ON f.id = i.frontend_id
LEFT JOIN oc_ekstri_frontend_view v
ON v.ekstri_id = i.id AND
v.product_id = ?
WHERE
f.subcat_id = ? AND
v.ekstri_id IS NULL;
I use ?
placeholders in the above query to suggest that you use a prepared statement rather than concatenating in your parameters. If you don't know what prepared statements are in PHP, you should read about them.
Upvotes: 1