H
H
Hazrat Hajikerimov2014-02-21 15:07:00
PHP
Hazrat Hajikerimov, 2014-02-21 15:07:00

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

screen.png

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Rsa97, 2014-02-21
@hazratgs

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.

A
Alexander Kind, 2014-02-21
@shineblu

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!

Y
Yuri Morozov, 2014-02-21
@metamorph

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 question

Ask a Question

731 491 924 answers to any question