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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:32:33+00:00 2026-05-12T15:32:33+00:00

My query is: SELECT business.name, AVG(rating.value) as total FROM business INNER JOIN rating ON

  • 0

My query is:

SELECT business.name, AVG(rating.value) as total  
FROM business   
INNER JOIN rating   
   ON business.id = rating.business_id   
INNER JOIN directory   
   ON business.id = directory.item_id  
WHERE directory.directory_id = 13    
   AND directory.type = 'business'   
   AND rating.rating_id = '1'   
GROUP BY business.id   
ORDER BY total DESC  

My problem is that I want to include any businesses even if they do not have any ratings associated with them?

  • 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-12T15:32:33+00:00Added an answer on May 12, 2026 at 3:32 pm

    You need to use LEFT JOIN instead of INNER JOIN:

    SELECT business.name, AVG(rating.value) as total  
    FROM business   
    INNER JOIN directory   
       ON business.id = directory.item_id  
    LEFT JOIN rating   
       ON business.id = rating.business_id AND rating.rating_id = '1'
    WHERE directory.directory_id = 13    
       AND directory.type = 'business'   
    GROUP BY business.id   
    ORDER BY total DESC
    

    If there are no ratings, total will be NULL.
    You can deal with this in MySQL (if you want) like this:

    IFNULL(AVG(rating.value), 'No ratings') as total 
    

    Also note you need to move the rating.rating_id = '1' to the JOIN conditions.

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

Sidebar

Related Questions

Query: SELECT u.user_id,r.totalVotes votes,r.totalPoints rating,@row:=@row+1 rank FROM mismatch_user u LEFT JOIN ratingItems r ON
this query SELECT * FROM tblContracts LEFT JOIN tblPartys ON tblContracts.id = tblPartys.Contract_id INNER
SQL query: SELECT ArticleCategories.Title AS Category, Articles.Title, Articles.[Content], Articles.Date FROM ArticleCategories INNER JOIN Articles
Query: SELECT DISTINCT ([Equipment List].ID) AS Expr1, [Job Assignments].Job FROM [Equipment List] LEFT JOIN
My Query SELECT DATE, SEC_TO_TIME( SUM( TIME_TO_SEC( `total_hours` ) ) ) AS total FROM
this is the mysql query SELECT * FROM users AS up JOIN users AS
i have this sql query select * from table where name like ? but
SELECT bp.*,r.rating,COUNT(r.review_for),bp.business_name,bp.profile_member FROM ibf_business_reviews r LEFT JOIN ibf_business_profiles bp ON ( r.review_for=bp.profile_member ) WHERE
I have this query SELECT *, bp.product_id FROM builder_product as bp JOIN builder_step as
I tried to write the following inner join query using an Oracle database: SELECT

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.