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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:13:58+00:00 2026-05-12T23:13:58+00:00

I have a MySQL database that looks like this: users ( id , name

  • 0

I have a MySQL database that looks like this:

users
    ( id , name )
groups
    ( id , name )
group_users
    ( id , group_id , user_id )

Now to look up all the groups that a user belongs to, I would do something like this:

select * from 'group_users' where 'user_id' = 47;

This will probably return something like:

( 1 , 3 , 47 ),
( 2 , 4 , 47 ),

But when I want to display this to the user, I’m going to want to display the name of the groups that they belong to instead of the group_id. In a loop, I could fetch each group with the group_id that was returned, but that seems like the wrong way to do it. Is this a case where a join statement should be used? Which type of join should I use and how would I use it?

  • 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-12T23:13:58+00:00Added an answer on May 12, 2026 at 11:13 pm

    In general, you want to reduce the total number of queries to the database, by making each query do more. There are many reasons why this is a good thing, but the main one is that relational database management systems are specifically designed to be able to join tables quickly and are better at it than the equivalent code in some other language. Another reason is that it’s usually more expensive to open many little queries than it is to run one large query that has everything you’ll end up needing.

    You want to take advantage of your RDBMS’s strengths, so you should try to push data access into it in a few big queries rather than lots of little queries.

    Now, that’s just a general rule of thumb. There are cases when it’s better to do some things outside of the database. It’s important that you determine which is the right case for your situation by looking into bottlenecks if and only if they occur. Don’t spend time worrying about performance until you find a performance problem.

    But, in general, it’s better to handle joins, lookups and all other query-related tasks in the database itself than it is to try to handle it in a general-purpose language.

    That said, the kind of join you want is an inner join. You’d structure your join query like this:

    SELECT groups.name, group_users.user_id
    FROM group_users
    INNER JOIN groups
      ON group_users.group_id = groups.group_id
    WHERE groups.user_id = 47;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have data in an MYSQL database that looks like this: Project Date Time
I have a table in a MSSQL database that looks like this: Timestamp (datetime)
I have to look into solutions for providing a MySQL database that can handle
I have a mysql database that is tracking hockey stats. What I'd like to
I have a MySQL database that I want to archive . What is the
I have a MySQL database that has on the order of 400 million innodb_data_pending_reads
I have a MySql database that stores a timestamp for each record I insert.
The code below works great. I have a MySQL database that contains book titles
We have a live MySQL database that is 99% INSERTs, around 100 per second.
I have a MySQL database, and a particular table in that database will need

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.