Simplifying your table & column names for human readability and less typing ...
+------+----------------+-------+----------+
| id | id_marketplace | label | property |
+------+----------------+-------+----------+
| 1 | 10 | 3 | 0 |
| 2 | 10 | 6 | 35 |
| 4 | 10 | 10 | 22 |
| 5 | 10 | 9 | 0 |
| 6 | 11 | 3 | 0 |
| 7 | 11 | 6 | 5 |
| 8 | 11 | 7 | 7 |
| 9 | 11 | 7 | 10 |
| 10 | 11 | 10 | 21 |
| 11 | 12 | 3 | 0 |
| 12 | 12 | 6 | 5 |
| 13 | 12 | 7 | 8 |
| 14 | 12 | 7 | 9 |
| 15 | 12 | 10 | 21 |
| 16 | 13 | 3 | 0 |
| 17 | 13 | 6 | 35 |
| 18 | 13 | 7 | 7 |
| 19 | 13 | 7 | 8 |
| 20 | 13 | 10 | 20 |
+------+----------------+-------+----------+
Your second query condition ...
(`id_marketplace_properties_label` = 6 AND `id_marketplace_properties` = 35 ) AND
(`id_marketplace_properties_label` = 7 AND `id_marketplace_properties` = 7 )
would require that columns have two different values simultaneously---obviously not possible. So we need to clarify your requirement. You want the id_marketplace values for which ...
A there is a row where label=6 AND property=5)
OR
B there is a row where label=6 AND property=35, and another row where label=7 AND property=7.
The query for A is simple ...
SELECT id_marketplace
FROM mpu
WHERE label=6 AND property=5;
+----------------+
| id_marketplace |
+----------------+
| 11 |
| 12 |
+----------------+
The query for B isn't so simple ...
SELECT a.id_marketplace
FROM mpu a
JOIN mpu b
ON a.id_marketplace=b.id_marketplace
AND a.label=6 AND a.property=35
AND b.label=7 AND b.property=7;
+----------------+
| id_marketplace |
+----------------+
| 13 |
+----------------+
or mebbe a little more efficiently ...
SELECT id_marketplace
FROM mpu
WHERE (label=6 AND property=35) OR (label=7 AND property=7)
GROUP BY id_marketplace
HAVING COUNT(*) >=2;
You want id_marketplaces for condition A OR B; that's most efficiently got with a UNION ...
SELECT id_marketplace
FROM mpu
WHERE label=6 AND property=5
UNION
SELECT a.id_marketplace
FROM mpu a
JOIN mpu b ON a.id_marketplace=b.id_marketplace AND a.label=6 AND a.property=35 AND b.label=7 AND b.property=7;
+----------------+
| id_marketplace |
+----------------+
| 11 |
| 12 |
| 13 |
+----------------+
Edited 1 time(s). Last edit at 01/19/2014 12:40PM by Peter Brawley.