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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:24:16+00:00 2026-05-10T22:24:16+00:00

The following query returns strange results for me: SELECT `Statistics`.`StatisticID`, COUNT(`Votes`.`StatisticID`) AS `Score`, COUNT(`Views`.`StatisticID`)

  • 0

The following query returns strange results for me:

SELECT     `Statistics`.`StatisticID`,     COUNT(`Votes`.`StatisticID`) AS `Score`,     COUNT(`Views`.`StatisticID`) AS `Views`,     COUNT(`Comments`.`StatisticID`) AS `Comments` FROM `Statistics` LEFT JOIN `Votes` ON `Votes`.`StatisticID` = `Statistics`.`StatisticID` LEFT JOIN `Views` ON `Views`.`StatisticID` = `Statistics`.`StatisticID` LEFT JOIN `Comments` ON `Comments`.`StatisticID` = `Statistics`.`StatisticID` GROUP BY `Statistics`.`StatisticID` LIMIT 0, 10 

I’m querying this on a table structure like the following:

(only data relevant to Statistics.StatisticID = 8)

Votes

StatisticID     8 

Views

StatisticID     8     8 

Comments

StatisticID     8     8     8     8     8 

Now if I run this query I get the following result set:

StatisticID    Score    Views   Comments      8           5        5        5 

I knwo where the 5 comes from – the number of Comments – and this works if I take the comments statement out. Can anyone debug this as this is out of my reach (I’m relatively new with SQL).

Thanks, Ross

  • 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. 2026-05-10T22:24:17+00:00Added an answer on May 10, 2026 at 10:24 pm

    Assuming you have an id field or similar on the votes/views/comments:

    SELECT     `Statistics`.`StatisticID`,     COUNT(DISTINCT `Votes`.`VoteID`) AS `Score`,     COUNT(DISTINCT `Views`.`ViewID`) AS `Views`,     COUNT(DISTINCT `Comments`.`CommentID`) AS `Comments` FROM `Statistics` LEFT JOIN `Votes` ON `Votes`.`StatisticID` = `Statistics`.`StatisticID` LEFT JOIN `Views` ON `Views`.`StatisticID` = `Statistics`.`StatisticID` LEFT JOIN `Comments` ON `Comments`.`StatisticID` = `Statistics`.`StatisticID` GROUP BY `Statistics`.`StatisticID` LIMIT 0, 10 

    Not tested it, but think it should work. (We have to use the different field because the statisticID will always be the same within a given group …)

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

Sidebar

Ask A Question

Stats

  • Questions 69k
  • Answers 69k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The easiest way is to use System.Xml.XmlDocument or System.Xml.Linq.XDocument to… May 11, 2026 at 12:33 pm
  • added an answer This code works (but not with comment) : { scopeName… May 11, 2026 at 12:33 pm
  • added an answer See the MSDN docs for the LoadIFilter function - you… May 11, 2026 at 12:33 pm

Related Questions

Why would the following query return Error converting data type varchar to bigint? Doesn't
Using MySQL syntax, how would I write a query to return the following (I
The following query does what I'd like it to do, however, I have no
The following query will display all Dewey Decimal numbers that have been duplicated in
Consider the following 2 tables: Table A: id event_time Table B id start_time end_time
I have a simple database with two tables. Users and Configurations. A user has
The following query returns a single row, as desired. The 'contracts' table has 6
I'm executing the following query: Select guiPolygonID, dbo.fn_Yval(p1X, p1Y, p2X, p2Y, 4.003318) From [vPolygonSegments]

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.