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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:04:04+00:00 2026-06-08T08:04:04+00:00

I have the following code: SELECT q25, ( ( AVG( q1 ) + AVG(

  • 0

I have the following code:

SELECT q25, (
(
AVG( q1 ) + AVG( q2 ) + AVG( q3 ) ) /3 ) AS Overall
FROM t_results
WHERE brand =  'XYZ'
AND DATE =  'MAY2012'
GROUP BY q25
ORDER BY Overall 
DESC LIMIT 1

If there is no data found by the query phpmyadmin returns the following message (which is quite correct):

MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0178 sec )

However, what I’d like is to actually return a NULL value, is this possible? I appreciate this might not be best practise but I’m working with inherited code and this might be the simplist and quickest route to a solution.

Thanks as always,

H.

  • 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-08T08:04:05+00:00Added an answer on June 8, 2026 at 8:04 am

    Create a table with exactly one row. Then you can use left join to achieve the desired NULL result.

    CREATE TABLE dummy (d TINYINT NOT NULL);
    INSERT INTO dummy SET d = 1;
    
    SELECT q25,
           ( ( AVG( q1 ) + AVG( q2 ) + AVG( q3 ) ) /3 ) AS Overall
    FROM dummy LEFT JOIN t_results
      ON brand = 'XYZ'
     AND DATE = 'MAY2012'
    GROUP BY q25
    ORDER BY Overall DESC
    LIMIT 1
    

    You can also replace the dummy table with a subquery:

    SELECT q25,
           ( ( AVG( q1 ) + AVG( q2 ) + AVG( q3 ) ) /3 ) AS Overall
    FROM (SELECT 1) AS dummy LEFT JOIN t_results
      ON brand =  'XYZ'
     AND DATE =  'MAY2012'
    GROUP BY q25
    ORDER BY Overall DESC
    LIMIT 1
    

    Tested this via sqlfiddle, where you can also experiment with alternatives.

    The conditions selecting the result, which used to be in the WHERE clause, now have to go into the ON clause. Otherwise the left join would produce non-NULL rows which would be removed by the WHERE, instead of generating a single NULL row if no matching row could be found. If there were no WHERE conditions in the original query, ON 1 could be used to express any row matches.

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

Sidebar

Related Questions

I have following code.. $query = SELECT quote, author FROM quotes ORDER BY id
I have the following code: SELECT <column>, count(*) FROM <table> GROUP BY <column> HAVING
All, I have the following code: $qry = Select * from vendor_options order by
I have the following code: $catsQuery = SELECT id, category FROM categories ORDER BY
I Have following code with LINQ var q = (from web in DataContext.Webs select
I have the following code: function isValidAuthor($authorID){ $query = SELECT * FROM jos_users WHERE
I have the following code $result = $handle->select()->from('store_details') ->where('store_details.store_id=?', $id) ->columns('store_details.store_name'); //->query(ZEND_DB::FETCH_OBJ); However, when
I have the following code: $sql = SELECT name, address, city FROM tableA, tableB
Let's say that I have the following code: SELECT * FROM table where company
I have the following SQL code: select val.PersonNo, val.event_time, clg.number_dialed from vicidial_agent_log val join

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.