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

The Archive Base Latest Questions

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

I have 2 tables. One is items and another is votes for those items.

  • 0

I have 2 tables. One is items and another is votes for those items.

Items table has: |item_id|name|post_date
Votes table has: |votes_id|item_id|answer|total_yes|total_no

What I want to do is show all items based on post_date and show the answer in the votes table with the HIGHEST total_yes. So I want to show only a SINGLE answer from the votes table with the highest total_yes vote.

I was trying:

SELECT a.*, b.* FROM Items a
INNER JOIN Votes b ON a.item_id = b.item_id
GROUP by a.item_id
ORDER by a.post_date DESC, b.total_yes DESC

But that doesnt work.

The result I would like to see is:

<item><answer><yes votes>
Buick | Fastest | 2 yes votes
Mercedes | Shiny | 32 yes votes
Honda | Quick | 39 yes votes

Any help is appreciated!

  • 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-12T13:32:02+00:00Added an answer on May 12, 2026 at 1:32 pm
    SELECT a.*, b.*
      FROM Items a
           LEFT JOIN Votes b on a.item_id = b.item_id
                             and b.total_yes = (select max(total_yes) 
                                                  from Votes v 
                             where v.item_id = a.item_id)
    ORDER BY a.post_date DESC, b.total_yes DESC
    

    N.B.: if you have for an item 2 answers with the same total_yes = max, you will have 2 rows for that item.

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

Sidebar

Related Questions

In MySQL, I have two tables with a 1:n relationship. Table items has products,
I have two MySQL tables: One for items and another to log purchases. I'm
I have a table name BRANDS. I have another table named MODELS. The tables
I have two tables, one called cart and one called items. Now I want
I have two tables : one table it matchs and the other is teams.
I have ten master tables and one Transaction table. In my transaction table (it
I have SMO code which copies tables from one database to another. It runs
I have tables item and store (it's a store management system). item table has
I have a purchase order table and another table to contain the items within
I want to copy one table to another one. For example I have table

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.