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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:15:21+00:00 2026-05-25T12:15:21+00:00

Below is a simple query for a click tracker. I’ve had a look at

  • 0

Below is a simple query for a click tracker. I’ve had a look at a lot of other posts and I’m scratching my head. I cannot get this query to work so that all rows from the calendar table (one calendar day per row) are displayed:

SELECT DATE_FORMAT(calendar_date, '%a %D') AS calendar_date, 
count( tracker_id ) as clicks
FROM calendar
LEFT JOIN offer_tracker USING(calendar_id)
WHERE 
  calendar_month = Month(CURDATE()) AND 
  calendar_year = Year(CURDATE()) AND ( offer_id = 4 OR offer_id IS NULL )
GROUP BY calendar_date;

It’s nearly there but not all rows in the calendar table are returned i.e. there is no Fri 2nd, Tue 6th, Wed 7th etc:

result set

Does anyone have any ideas on where I’m going wrong? Should I be using a subquery?

  • 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-05-25T12:15:22+00:00Added an answer on May 25, 2026 at 12:15 pm

    I guess the offer_id is from the offer_tracker table. When you have an (left) outer join, and you use a field from the right table in a WHERE condition (like your offer_id = 4), the join is actually cancelled and gives same results as an inner join.

    The attempt to lift the cancellation (offer_id = 4 OR offer_id IS NULL) does not work as you expect. Any row from offer_tracker with offer_id <> 4 has already passed the LEFT JOIN but is removed because of the WHERE condition. So, no row with Friday 2nd will appear in the results if there is a row with offer_id different than 4 for this date.


    Move the offer_id = 4 check to the LEFT JOIN, instead:

    SELECT DATE_FORMAT(calendar_date, '%a %D') AS calendar_date
         , count( tracker_id ) as clicks
    FROM calendar
      LEFT JOIN offer_tracker 
        ON  offer_tracker.calendar_id = calendar.calendar_id
        AND offer_id = 4
    WHERE calendar_month = Month(CURDATE())
      AND calendar_year = Year(CURDATE()) 
    GROUP BY calendar_date
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Putting a super simple query tool together shown below: Problem: How do I get
This might be a very simple thing. Check out the normal sql query below
I have a simple query as listed below SELECT id, name, email FROM users
I cannot understand why this simple query is not created. I call this method
I am getting a MismatchedTreeNodeException throw with the simple query below using NHibernate 3.2.0.4000.
Have just got a surprise and would appreciate some suggestions. The simple query below
I am writing a simple query as below const char *sql = insert into
I ran the following simple query that looks like the example below: (Briefly; one
I have a simple query as shown below var trips = from t in
Below is a simple Linq-to-SQL query to delete an address record associated with a

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.