Answer the question
In order to leave comments, you need to log in
Duplicate record, what's wrong with SQL query?
Hello, I am doing a selection of goods from several tables. For some reason, one of the entries is duplicated when I select a media file:
SELECT t5.file_url, t1.slug, t1.product_name, t1.virtuemart_product_id, t3.product_price FROM $products as t1
LEFT JOIN $product_categories as t2 ON t1.virtuemart_product_id=t2.virtuemart_product_id
LEFT JOIN $product_prices as t3 ON t1.virtuemart_product_id=t3.virtuemart_product_id
LEFT JOIN $products_medias as t4 ON t1.virtuemart_product_id=t4.virtuemart_product_id
LEFT JOIN $medias as t5 ON t4.virtuemart_media_id=t5.virtuemart_media_id
WHERE t2.virtuemart_category_id = 1824
Answer the question
In order to leave comments, you need to log in
because LEFT JOIN is used, then one record from the $products table may have several of the others, which is why duplication occurs.
To avoid this, you need to use grouping:GROUP BY t1.virtuemart_product_id
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question