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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:28:46+00:00 2026-05-29T17:28:46+00:00

I have this simple MySQL statement: SELECT ((AVG(q1) + AVG(q8) + AVG(q15)) / 3

  • 0

I have this simple MySQL statement:

 SELECT 
   ((AVG(q1) + AVG(q8) + AVG(q15)) / 3 ) AS Res  
 FROM tresults 
 WHERE id = '1' AND date = 'MARCH2010' AND q25 = '1'
 GROUP BY q25

Now, if there are no rows with the date MARCH2010 then the query returns zero results (which is correct) but I’d like it to return a row – even if the result is NULL.

  • 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-29T17:28:53+00:00Added an answer on May 29, 2026 at 5:28 pm

    You can just select a single row as a constant, and then left join it to your result set:

    select l.*, r.* 
    from (select "your constant" as constant) as l 
    left join ( 
      SELECT 
         ((AVG(q1) + AVG(q8) + AVG(q15)) / 3 ) AS Res  
       FROM tresults 
       WHERE id = '1' AND date = 'MARCH2010' AND q25 = '1'
       GROUP BY q25
    ) as r on 1
    

    How this works:

    • select "your constant" as constant always returns a single row
    • left join always returns all of the rows in the left table at least once
    • if the right table has no rows, then the entire left table is extended with a bunch of null columns, and the result has one row
    • if the right table has n rows, the result has n rows that each have an additional “your constant” column
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple MySQL select statement: SELECT COUNT(*) AS COUNT FROM MY_TABLE WHERE
I'm having a simple select statement using php-mysql and I have this script to
i have this simple type from an external webservice: <xsd:element name=card_number maxOccurs=1 minOccurs=1> <xsd:simpleType>
I have a table in a MySQL database that I am running simple SELECT
I have a table that I need a MYSQL Select statement so I can
I'm trying to do a simple select statement on a mysql database. In MsSql
I have this simple regex, [\d]{1,5} that matches any integer between 0 and 99999.
I have this simple Jsp page: <%@ page language=java import=java.awt.Color%> <% Color background =
I have this simple php script <?php echo '<pre>'; // Outputs all the result
I have this simple example I can't seems to get working : MERGE INTO

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.