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

  • Home
  • SEARCH
  • 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 89735
In Process

The Archive Base Latest Questions

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

I know you can combine multiple table-selects using a Join statement but is there

  • 0

I know you can combine multiple table-selects using a Join statement but is there a way to combine these two queries into one?

SELECT Statistics.StatisticID FROM Statistics ORDER BY `SubmittedTime` DESC LIMIT 0, 10 

And this one?

SELECT COUNT(Votes.StatisticID) FROM Votes WHERE Votes.StatisticID = ? 

(fluff removed)

At the moment I’ve achieved something that nearly works.

SELECT Statistics.StatisticID, COUNT(Score.StatisticID) AS Votes FROM `Statistics` LEFT JOIN `Votes` AS `Score` ON `Statistics`.`StatisticID` = `Score`.`StatisticID` ORDER BY `SubmittedTime` DESC LIMIT 0, 10 

The Votes table is a simple StatID, UserID joiner. In my test case it contains 3 rows, two with StatID 5 – 1 with StatID 2.

My query will work if I add a WHERE clause, for example WHERE StatisticID = 5 and correctly return 2 votes. However if I remove the WHERE clause I still get one row returned and 3 votes.

Is it possible to combine these queries or will I have to run the second for each result (obviously not preferable)?

  • 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:45:48+00:00Added an answer on May 10, 2026 at 10:45 pm

    Assuming that you want to count the number of votes per statistics

    SELECT StatisticID, COUNT(*) AS CountVotes FROM `Votes` GROUP BY Statistics.StatisticsID 

    I’m not seeing the reason why the tables have to be joined.

    [EDIT] Ah…I see you want to order by submittedtime of the statistics table.

    SELECT Votes.StatisticID, COUNT(*) AS CountVotes FROM `Votes` JOIN Statistics ON votes.statisticsID = Statistics.StatisticsID GROUP BY Statistics.StatisticsID ORDER BY Statistics.SubmittedTime 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 90k
  • Answers 90k
  • 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
  • Editorial Team
    Editorial Team added an answer What you describe here is a known plaintext attack. The… May 11, 2026 at 6:08 pm
  • Editorial Team
    Editorial Team added an answer The question you refer do doesn't use JavaScript to access… May 11, 2026 at 6:08 pm
  • Editorial Team
    Editorial Team added an answer I think the answer in your case is to utilise… May 11, 2026 at 6:08 pm

Related Questions

I know that you can insert multiple rows at once, is there a way
I need to search across multiple columns from two tables in my database using
Using POSIX threads & C++, I have an Insert operation which can only be
How can I get the Cartesian product (every possible combination of values) from a

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.