Could someone please explain me how I could improve a query like this so it runs as fast as possible and it is also cleaner? As you can see I have 2 selects which are exactly the same, but I need to be able to the get the count out of this all, so I'm not sure what would be the best way to change something like this:

```
SELECT COUNT(*) AS count FROM users
WHERE users.activated = '1'
AND (SELECT TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) FROM users AS users2 WHERE users2.id = users.id) >= '18' 
AND (SELECT TIMESTAMPDIFF(YEAR, birthdate, CURDATE()) FROM users AS users2 WHERE users2.id = users.id) <= '28'

```

Basically I need to get the count of all users which are between 18 and 28 years old for example. `users.birthdate` is a date column.

Could someone please help? How would I be able to use the 2 `select`s from the `where` clause as just one so it doesn't execute the same thing 2 times?

EDIT:

Another example, I also have this query which I need to use multiple times in a where clause:

```
SELECT COUNT(*) AS count FROM users
 WHERE ROUND((DEGREES(ACOS(SIN(RADIANS('$c_lat')) * SIN(RADIANS(users.lat)) + COS(RADIANS('$c_lat')) * COS(RADIANS(users.lat)) * COS(RADIANS('$c_lng' - users.lng))))) * 60 * 1.1515 * 1.60934 * 1000) >= 1000
 AND ROUND((DEGREES(ACOS(SIN(RADIANS('$c_lat')) * SIN(RADIANS(users.lat)) + COS(RADIANS('$c_lat')) * COS(RADIANS(users.lat)) * COS(RADIANS('$c_lng' - users.lng))))) * 60 * 1.1515 * 1.60934 * 1000) <= 5000

```

This one gets all the users which are between a distance of 1000 meters and 5000 meters from $c\_lat and $c\_lng that I pass.

Just trying to understand what's the best way to solve these kind of problems in MySQL.

Thanks!