Answer the question
In order to leave comments, you need to log in
MySQL returns the same item
Below is the SQL query, the problem is that it outputs the same product 4 times.
How to explain to MySQL that it is necessary not to display the same.
SELECT * FROM `catalog` as c
INNER JOIN atributes AS a1 ON c.art = a1.art
INNER JOIN atributes AS a2 ON c.art = a2.art
WHERE c.catalog_3 = "Видеокарты"
AND c.price != "0"
AND c.avail != "0"
AND a1.names = "Производитель"
AND a1.value = "ASUS"
AND a2.names = "Графический процессор"
AND a2.value = "AMD Radeon HD 7770"
ORDER BY price ASC LIMIT 0, 15
Answer the question
In order to leave comments, you need to log in
You have one product with `catalog`.`id`=97 has twice the attribute "Manufacturer" in the description (`attributes`.`id`=4426 and `attributes`.`id`=394) and twice the attribute "GPU" (`attributes`.`id`=395 and `attributes`.`id`=4427). Thus, the product of sets gives four options:
(97, 4426, 395)
(97, 394, 395)
(97, 4426, 4427)
(97, 394, 4427
) GROUP BY `c`.`id`
work will be added.
Good afternoon,
Add DISTINCT after SELECT (and if all fields returned by the query are the same, only 1 record will be displayed)
Good luck!
In your atributes table, records with id 4426 and 394 have the same article numbers (708089), hence the duplication.
In theory, this should not be so, fix it, put a check on unique.
If this is some kind of ingenious move, then I can’t offer anything better than group by id (which, by the way, is completely wrong from the point of view of sql, the correct solution is somewhat longer, but mysql also hides this).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question