I have a users table with a dob (date of birth) field, in a postgres database.
I want to write a query that will retrieve the next five upcoming birthdays. I think the following needs to be considered -
- Sorting by date of birth won't work because the years can be different.
- You want the result to be sorted by date/month, but starting from today. So, for example, yesterday's date would be the last row.
- Ideally, I would like to do this without functions. Not a deal breaker though.
Similar questions have been asked on SO, but most don't even have an accepted answer. Thank you.
Well, this got downvoted a lot. But I'll post my answer anyway. One of the answers helped me arrive at the final solution, and that answer has been deleted by its owner for some reason.
Anyway, this query works perfectly. It gives the next 5 upcoming birthdays, along with the dates.