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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:18:52+00:00 2026-05-20T16:18:52+00:00

I have a user table with id, username and food_id columns. The idea is

  • 0

I have a user table with id, username and food_id columns. The idea is the users store their favourite food and we come up with a league table of foods. I want to generate a report of the top votes for the each food type. I am using MySQL and PHP.

For clarity, here is an example of the table:

 id  food_id   username
 1   1         Bob
 2   100       Jane
 3   200       Andy
 4   1         Maggy
 5   100       Rich
 6   100       Mick
 7   1         Kevin

I have a query that user ‘renegm’ on Stackoverflow gave me. It give me the results of the food survey. The query is:

select food_id, count(*) score
   from myTable
group by food_id
order by score desc limit 100

It gives me the results perfectly as in:

food_id   score
1         3
100       4

I realised after I got the answer that I am getting food_ids and not names.

I need to do a join on food table. It looks like

food_id    food_name
1          Salad
100        Burgers

How do I incorporate the join into the above query? I have looked at my books but can’t quite work it out.

  • 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-20T16:18:52+00:00Added an answer on May 20, 2026 at 4:18 pm
    select f.food_id,
           n.food_name,
           count(f.food_id) score
      from myTable
      left join food_names n 
             on n.food_id = f.food_id
    group by f.food_id,
             n.food_name
    order by score desc limit 100
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a user table with id, username and food_id columns. The idea is
I have a table of users with three columns. Username Accepted Rejected User 1
I have a User table where there are a Username and Application columns. Username
I have a user table with userid and username columns, and both are unique.
I have three tables: Users, Groups and GroupsUsers User table: id: 1 username: admin
In SQL Server 2008 I have a user table like the following: Userid Username
I have two tables, a user table and a application table: User id username
I have 4 tables. Table A that has users - ( user_id, username, and
I have a User table that has all of their avatars saved in an
I have a user table 'users' that has fields like: id first_name last_name ...

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.