Mysql
 sql >> Database >  >> RDS >> Mysql

MySQL - cambia OR in AND

Puoi provare con having :

SELECT Ads.AdId 
FROM Ads 
JOIN AdsAmenities ON Ads.AdId = AdsAmenities.ads_AdId 
WHERE AdsAmenities.amenities_AmenityId IN (2, 18, 1) 
GROUP BY Ads.AdId
HAVING COUNT(distinct AdsAmenities.amenities_AmenityId) = 3

Nel caso AdsAmenities.amenities_AmenityId i valori sono uniq, puoi saltare il distinct parte.