I’m using mysql 5.1
Here is my request,
I want to count the number of users who are between 0 to 14 years old and with an enable account.
SELECT COUNT( DISTINCT user.id ) AS user
FROM profile, user
WHERE (
profile.age
BETWEEN 0
AND 14
)
AND user.enabled =1
The user.enabled=1 condition is working, but not the profile.age BETWEEN 0 AND 14
You aren’t joining the 2 tables together therefore you are simply running the cartesian product of the two. You need to join them by a common key.
Something like this: