Use: sort by users whose age is closest to a defined age. In the example below, 25 years.

User Age
1 25
3 23
4 26
5 27


The MySQL function abs ensures that the subtracted result is always positive.
The date of birth is what’s commonly stored in the database, so the query will look as follows:

25 can be replaced by any age to align the results by.

About Gugulethu Ncube

IT enthusiast getting things done.