SELECT `hotels`.*,
(SELECT AVG(rating)
FROM hotelreviews WHERE hotel_id = hotels.id
WHERE (rating IS NOT NULL AND rating > 0)
GROUP BY hotel_id) AS `avgrating`
FROM `hotels`
WHERE (id = '2791')
Als ik de 'WHERE' weglaat uit de subquery, gaat het goed, echter wanneer ik de voorwaarden toevoeg geeft mysql een fout. Zo'n typische fout waarmee je denkt, wat is er?
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE (rating IS NOT NULL AND rating > 0) GROUP BY hotel_id) AS `avgrating` FROM' at line 1