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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:24:09+00:00 2026-06-13T04:24:09+00:00

I currently have the following SQL statement MySQL Query: SELECT c.day, COUNT(*) FROM calendar

  • 0

I currently have the following SQL statement

MySQL Query:

SELECT
    c.day,
    COUNT(*)
FROM
    calendar c
JOIN
    visitors d
ON  DAYOFMONTH(d.created) = c.day
WHERE
    c.day BETWEEN DAYOFMONTH('2012-10-01') AND DAYOFMONTH('2012-10-31')
AND
    site_id = 16
GROUP BY
    DAYOFMONTH(d.created)
ORDER BY
    DAYOFMONTH(d.created)

My Tables:

Calendar

id  | day
---------
1   | 1
2   | 2
3   | 3
...
31  | 31

Visitors

id  | site_id | created
-----------------------------------
1   | 16      | 2012-10-18 11:14:39
2   | 16      | 2012-10-18 11:15:17
3   | 11      | 2012-10-18 11:49:14
4   | 11      | 2012-10-18 11:49:43
5   | 16      | 2012-10-19 11:54:37
6   | 1       | 2012-10-19 05:56:31
7   | 2       | 2012-10-19 05:57:56

I have created the table, calendar as prescribed in this answer but I seem to still get the same information. I am only getting the dates where I have data.

day    |   COUNT(*)
---------------------
18     |   2
19     |   1

I need to also retrieve 0 on the dates that have no data.

UPDATE:

I tried this:
SELECT *
FROM calendar c
LEFT JOIN visitors d
ON  DAYOFMONTH(d.created) = c.day

and

SELECT *
FROM calendar c
LEFT JOIN visitors d
ON  DAYOFMONTH(d.created) = c.day
WHERE  site_id = 16

I can confirm that the site_id = 16 is certainly the one killing the results.

  • 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-13T04:24:11+00:00Added an answer on June 13, 2026 at 4:24 am

    use LEFT JOIN instead of INNER JOIN

    SELECT ...
    FROM   calendar c 
           LEFT JOIN  visitors d
             ON DAYOFMONTH(d.created) = c.day
    WHERE...
    

    INNER JOIN retrieves only rows which has atleast one match on the other table while LEFT JOIN retrieves all rows define on the lefthand side table whether it has a match or none on the other table(s).

    UPDATE 1

    SELECT  c.day,
            COUNT(*)
    FROM    calendar c
            LEFT JOIN
            (
                SELECT *
                FROM   visitors
                WHERE  site_id = 16
            ) d ON  DAYOFMONTH(d.created) = c.day
    WHERE c.day BETWEEN DAYOFMONTH('2012-10-01') AND DAYOFMONTH('2012-10-31')
    GROUP BY DAYOFMONTH(c.day)
    ORDER BY DAYOFMONTH(c.day)
    

    **UPDATE by Thorpe Obazee

    SELECT  c.day,
            COUNT(site_id)
    FROM    calendar c
            LEFT JOIN
            (
                SELECT *
                FROM   visitors
                WHERE  site_id = 16
            ) d ON  DAYOFMONTH(d.created) = c.day
    WHERE c.day BETWEEN DAYOFMONTH('2012-10-01') AND DAYOFMONTH('2012-10-31')
    GROUP BY c.day
    ORDER BY c.day
    

    We cannot use COUNT(*) since it will return 1 every day. We also should not use DAYOFMONTH on c.day in the GROUP BY and ORDER BY since it is already what we need.

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

Sidebar

Related Questions

I have the following sql statement: SELECT COUNT(table2.programName), table2.programName FROM table1 LEFT JOIN table2
I currently have the following SQL statement: SELECT s.first_name, s.last_name, tgs.group_identifier FROM staff s
I have the following SQL statement: SELECT r.Result AS Resuly, COUNT(f.fieldID) AS [Count] FROM
I currently have the following SQL statement in a Stored Procedure; SELECT [Id], [Path],
I currently have the following SQL query that lists all the names of all
I have the following sql create statement mysql> CREATE TABLE IF NOT EXISTS `erp`.`je_menus`
I am currently running the following SQL statement on my MySQL database: INSERT INTO
I currently have a prepared statement in Java which uses the following SQL statement
I have the following SQl statement: SELECT id + 100000000000000000 AS id, a.external_code +
I currently have a large SQL statement which i add the following line to

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.