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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:36:53+00:00 2026-06-07T21:36:53+00:00

I have connected three tables to each other. I’m querying keywords + statistics. I

  • 0

I have connected three tables to each other.
I’m querying keywords + statistics.

I need to get data out by date range, and
if there is no data for that specific date range
i would like it to return 0 statistics

Lets say my query is:

SELECT keyword,SUM(stat) FROM keywords WHERE date >=’2012-07-10′ GROUP BY keyword;


It would return
|my keyword 1|3|
|my keyword 2|6|

Example table content:
| id | keyword          | stat | date            | keywordGroup |
| 1  | my keyword 1 | 2     | 2012-07-11 | 1 |
| 2  | my keyword 1 | 1     | 2012-07-12 | 1 |
| 3  | my keyword 2 | 6     | 2012-07-11 | 1 |
| 4  | my keyword 3 | 10   | 2012-07-09 | 1 |

But there are some keywords which have no stats for that date range
but I would still like to get those keywords showing 0 as stats.

Like this:

|my keyword 1|3|
|my keyword 2|6|
|my keyword 3|0|

The problem is that the where clause blocks values that are not found, is there a workaround.
As I said I have three tables with relations, I use LEFT JOIN to
query data, for simplification I left that part out of my example query.

Table: Campaigns
id
name

Table: KeywordGroup
id
name
campaign

Table: KeywordData
id
keyword
stat
date
keywordGroup

  • 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-07T21:36:55+00:00Added an answer on June 7, 2026 at 9:36 pm

    Assuming you are joing tables with left joins correctly, use:

    select keyword, ifnull(sum(stat),0) ... group by keyword
    

    If it is WHERE clause that filters out some stats before even grouping is applied, then you need to move the date condition into LEFT JOIN condition, ie.

    from KeywordGroup left join KeywordData on ... and date > '2012-07-10'
    

    But I cannot help further without seeing actual queries. 🙂

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

Sidebar

Related Questions

I have three entities: EntityA, EntityB and EntityC connected with to-many relationships. See schema
I have a Java application that parses files and stores the data I need
I have a SQL table with three columns X, Y, Z. I need to
I have connected to a table of the database and found a row by
I have connected to local and server database from local SqlServer 2005. How to
I have connected with the database successfully by using wizard in server explorer. but
I have a mp3 Player. I have connected it to my PC which has
I'm building my first MVC3 website and have connected my site to a mdf
I have never connected to a database in java before. May I know if
I have successfully connected my Oracle 11g XEdatabase with java in Netbeans 7.1. Class.forName(oracle.jdbc.OracleDriver);

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.