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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:48:32+00:00 2026-06-10T11:48:32+00:00

I have a bridging table that looks like this clients_user_groups id = int client_id

  • 0

I have a bridging table that looks like this

clients_user_groups
id = int
client_id = int
group_id = int

I need to find all client_id’s of of clients that belong to the same group as client_id 46l

I can achieve it doing a query as below which produces the correct results

SELECT client_id FROM clients_user_groups WHERE group_id = (SELECT group_id FROM clients_user_groups WHERE client_id = 46);

Basically what I need to find out is if there’s a way achieving the same results without using 2 queries or a faster way, or is the method above the best solution

  • 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-06-10T11:48:32+00:00Added an answer on June 10, 2026 at 11:48 am

    You’re using a WHERE-clause subquery which, in MySQL, ends up being reevaluated for every single row in your table. Use a JOIN instead:

    SELECT a.client_id
    FROM   clients_user_groups a
    JOIN   clients_user_groups b ON b.client_id = 46
                                AND a.group_id  = b.group_id
    

    Since you plan on facilitating clients having more than one group in the future, you might want to add DISTINCT to the SELECT so that multiple of the same client_ids aren’t returned when you do switch (as a result of the client being in more than one of client_id 46’s groups).

    If you haven’t done so already, create the following composite index on:

    (client_id, group_id)

    With client_id at the first position in the index since it most likely offers the best initial selectivity. Also, if you’ve got a substantial amount of rows in your table, ensure that the index is being utilized with EXPLAIN.

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

Sidebar

Related Questions

I have a Table containing some information that I need. All these rows also
I have a table that looks something like the following : PropertyID Amount Type
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
I know that this isn't exactly normalised, but bringing all of the localised data
I need to tidy up an array. And gather all similar information together. This
Many applications have grids that display data from a database table one page at
i have a table view that when the user taps on one of the
I have a very basic one table scenario; tblFamiles entryID : Int name: Text
I have been spending some time on this. My problem involves bringing back domain
have written this little class, which generates a UUID every time an object of

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.