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 8955441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:33:28+00:00 2026-06-15T14:33:28+00:00

SELECT User_JoinDate, COUNT(User_ID) FROM Users WHERE `User_JoinDate` BETWEEN ‘2012-11-22’ AND ‘2012-12-06’ GROUP BY User_JoinDate

  • 0
SELECT User_JoinDate, 
COUNT(User_ID) 
FROM Users WHERE `User_JoinDate` 
BETWEEN '2012-11-22' AND '2012-12-06' 
GROUP BY User_JoinDate 
ORDER BY User_JoinDate ASC"

I’m generating data to be displayed in a line graph. Unfortunately I can’t figure out how to get the above query to display 0 for a date that no users might have registered. So currently my output might be something like this:

2012-11-22 - 2
2012-11-25 - 4

But what I want is

2012-11-22 - 2
2012-11-23 - 0
2012-11-24 - 0
2012-11-25 - 4

I do currently have a working version which stores the MySQL result into an array and then PHP loops through and fills the blanks. This seems very messy and I was hoping there would be a solution through MySQL. I have had a good search of the site but struggling to understand some of the implementations. Any suggestions?

  • 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-15T14:33:29+00:00Added an answer on June 15, 2026 at 2:33 pm

    You can build out an automated result set using MySQL variables for all the dates you want.

    select
          AllDaysYouWant.MyJoinDate,
          count( U.User_ID ) as NumberJoined
       from
          ( select
                  @curDate := Date_Add(@curDate, interval 1 day) as MyJoinDate
               from
                  ( select @curDate := '2012-11-21' ) sqlvars,
                  Users
               limit 18 ) AllDaysYouWant
          LEFT JOIN Users U
             on AllDaysYouWant.MyJoinDate = U.User_JoinDate
       group by
          AllDaysYouWant.MyJoinDate
    

    The inner query, I am just joining to the users table with no key, so its just used to cycle through X number of records to represent the day span you want… This could be 30, 100, whatever…. Just as long a the table (in this case users), has as many records as you are expecting.

    THEN, that result of nothing but days is joined to the users table, but this time, based on the JOIN_DATE of the user. The simple COUNT() should get you what you want.

    The “AllDaysYouWant” is the alias assigned to the internal first part query of

      ( select
              @curDate := Date_Add(@curDate, interval 1 day) as MyJoinDate
           from
              ( select @curDate := '2012-11-21' ) sqlvars,
              Users
           limit 18 ) AllDaysYouWant
    

    This basically states… From the users table (but could be any), give me 18 rows of data (via limit, but could be almost any number of records, but you only need from Nov 22 to Dec 6, which is only 14 days, but I did 18 just for principle it could be almost anything. Above the Users table is (select @curDate := ‘2012-11-21’ ) sqlvars. Any select statement within a query that is wrapped in parentheses as a table source must be given an alias and since it is just a variable I’ll be using, don’t care what its name is. So, this query starts the variable at Nov 21 and the Select @curDate := Date_Add…blah blah states to take the current value of @curDate, add 1 day to it (now becomes Nov 22) and store it in the returned row “MyJoinDate”. So now, this inner query creates your table of just dates going from Nov 22 forward 18 days worth of data and has the alias “AllDaysYouWant” for the rest of the query to reference.

    I’ve adjusted the query which was probably what you encountered, to alias.field everything for clarification…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The first select is select user_id, count(*) as count from users where referrer IS
SELECT user_id, created FROM photo_comments GROUP BY user_id returns user_id created 1 2009-10-20 21:08:22
Say I have the following: $query = SELECT user_id,email,password, roles.role_id,role_name FROM users JOIN roles
This problem is baffling me: BEGIN; INSERT INTO sub_users(user_id, email) SELECT user_id FROM users
SELECT User, COUNT(User) as count FROM Tests GROUP by User; This works. However, if
SELECT User, COUNT(*) as count FROM Tests GROUP by User; This may return row,
$q = SELECT user_id FROM users WHERE partner='$qpartner' AND group_id='$gi' AND status='1'; $r =
My current query is as follows: SELECT user_id, sum(...) as total from mytable group
I have query like this SELECT user_id FROM user_rights ORDER BY user_id DESC; Why
my queries are : $select_userid_query = execute_pdo_query(SELECT user_id FROM users WHERE username=' . $_COOKIE['username']

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.