I have two tables "USERS" and "CALENDER", in calender table user place his availability dates, mean 1-to-many relationship.
Now i want to get user list by availability date (today date mean available for today), i.e: i want to show those user who are available today on the top, then those user who's availability in future and then show those user who haven't any availability (i.e: no record in calender).
I am trying with below query:
SELECT u.first_name, c.date
FROM users AS u
LEFT JOIN calendar AS c ON (c.uid = u.id)
GROUP BY u.id
ORDER BY DATE(c.date) ASC
but this will give me record by start by those user who have not any availability in calender and then those who have availability but in past. The results are given below:
User1 NULL User13 2012-12-12 00:00:00
User2 NULL User12 2012-12-12 00:00:00
User3 NULL User10 2012-12-23 00:00:00
User4 NULL User10 2012-12-24 00:00:00
User5 NULL User9 2012-12-25 00:00:00
User6 NULL - Want To look this => User8 2012-12-27 00:00:00
User7 2012-09-20 00:00:00 User7 2012-12-28 00:00:00
User8 2012-09-29 00:00:00 User1 NUL
User9 2012-10-25 00:00:00 User2 NUL
User10 2012-10-26 00:00:00 User3 NUL
User11 2012-10-27 00:00:00 User4 NUL
User12 2012-12-05 00:00:00 User5 NUL
User13 2012-12-10 00:00:00 User6 NUL