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

  • Home
  • SEARCH
  • 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 7720793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:45:36+00:00 2026-06-01T03:45:36+00:00

I want to return a row for every month in a range specified- what

  • 0

I want to return a row for every month in a range specified- what I’m having trouble with is- that if I do not have a row there is nothing returned; What i was want is the month name to be returned and winner_id to be null

my query so far.

SELECT MONTHNAME(dated) as Month, winner_id FROM competitions WHERE dated > '2012-01-01'

What i want my output to look like is

Month     Winner_id
-------------------
January   NULL
February  2654
March     19864
April     NULL

the problem is i do not have a row for january or april in the db- but i still want a month returned?

should i do the months in php and do individual queries for each month?

  • 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-01T03:45:38+00:00Added an answer on June 1, 2026 at 3:45 am

    There are ways to do this in MySql but it would be overkill in your case. I’d use a variation of your current query and fill the gaps in php:

    $res = mysql_query( "SELECT MONTH(dated) as month, winner_id".
                        " FROM competitions WHERE dated > '2012-01-01'");
    $months = array();
    for($i = 1; $i <= 6; ++$i) $month[$i] = 0;
    while($r = mysql_fetch_assoc($res)) {
        $month[$r['month']] = $r['winner_id'];
    }
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query that returns one row. However, I want to invert the
I want to return nothing when if condition is not met, for instance (if
I want to return all application dates for the current month and for the
I have a simple ArrayAdapter. I want to set up a listener for every
Situation: I have a ListView with my own ListAdapter . In every row I
I have a ListView that's populated from a SimpleCursorAdapter each row containing 3 different
I have a gridview that contains value of every rows read from a text
I have a query that searches through several tables and returns one row for
I have a 10 million+ row table that looks like this: id | time_read
I have a ListView where each row has a fixed height. Every row contains,

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.