Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8998877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:05:52+00:00 2026-06-16T00:05:52+00:00

I have two tables USERS and CALENDER, in calender table user place his availability

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:05:53+00:00Added an answer on June 16, 2026 at 12:05 am

    This problem can be solve by putting sub-query and get the future dates and then in ascending form will show exactly like in question, i.e: all available date record on the top then some future record and then show null value (if someone have no dates in calender).

    SELECT u.first_name, 
     (
      SELECT DATE( c.date ) FROM calendar AS c
      WHERE c.uid = u.id
      AND DATE( c.date ) >= CURDATE( )
      ORDER BY DATE( c.date ) ASC
      LIMIT 1
    ) AS availability
    FROM users AS u
    GROUP BY u.id
    ORDER BY IF( availability IS NULL , 1, 0 ) , availability
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables of concern here: users and race_weeks. User has many race_weeks,
I have two tables users registered_members I want to confirm values from user table
Assuming I have two tables: users and orders . A user has many orders,
I have two tables: messages (messages users posted), likes (many to many relationship between
I have two tables users and providers that have has_and_belongs_to_many relationship. The join table
I have two tables: Users and Roles. A user may have more roles, so
I have two tables: 'movies' and 'users'. There's an n:m relationship between those, describing
I have two tables - users and stores . there is a third table
I have two tables users table: id|name user_relationships id | user_id | friend_id and
I have two tables users and work_orders. Now I need to get work_orders results

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.