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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:22:53+00:00 2026-06-05T11:22:53+00:00

I want to count all rows from the game_votes where g_id is equal to

  • 0

I want to count all rows from the game_votes where g_id is equal to 14, it is working almost good, but if there aren’t any records with g_id = 14 it does still show 1 in the cnt field.

Here is my query:

SELECT
     SUM(vote) as vote,
     COUNT(*) as cnt
FROM (`games`)
LEFT JOIN `game_votes`
ON
     `game_votes`.`g_id` = `games`.`id`
WHERE `games`.`id` = '14'

Whats wrong? Am I missing something?

  • 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-05T11:22:57+00:00Added an answer on June 5, 2026 at 11:22 am

    You’re getting a count of 1 because COUNT(*) essentially counts the number of rows in your result set. Since you’re selecting a row out of your games table with an id of 14 and left joining that to the game_votes table, you’re going to always have 1 or more rows as long as there exists a game with an id of 14 regardless of whether or not it contains any corresponding votes in your game_votes table. Instead of COUNT(*), try COUNT(game_votes.g_id). If there are no votes, the g_id field will contain a null value, and COUNT() will not include a null value in its calculation.

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

Sidebar

Related Questions

I want to LIMIT Grouped results to 30, but instead I'm grouping all rows
I want to do a query that will count all the 'email' rows in
I want to Count all the rows that only have the value I want
Using MySQL 5.x I want to efficiently select all rows from table X where
I want to take the number of all the rows from a table in
I want to count the total number of order detail rows over all orders
I want to count all the rows and at the same time list them
Here comes the trouble. I want to delete all rows from datagridview. This how
We've got a PHP application and want to count all the lines of code
I have a string of sentences and want to count all of what I

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.