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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:47:15+00:00 2026-05-21T23:47:15+00:00

First off, sorry if the title is a little off. I’ll explain my situation

  • 0

First off, sorry if the title is a little off. I’ll explain my situation using an example.

I have a Groups table like this:

id  name
1   admin
2   developer
3   reviewer
4   beta tester
5   contributor

I then have a Permissions table like so:

id   user_id  group_id
1    60       1
2    60       2
3    60       3

What I want to do is use a JOIN query to end up with a result like this:

(perm.) name   part of group
admin          1
developer      1
reviewer       1
beta tester    0
contributor    0

I.e. If there is an entry for a certain user ID which links to a certain group ID, that user is in that group, so a 1 is put in the column. I’m using this to print out a list of checkboxes for an admin page.

My question is simply: how can this be done in MySQL? Obviously a JOIN of some kind, but they confuse the hell out of me. Thanks for any help.

James

  • 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-21T23:47:16+00:00Added an answer on May 21, 2026 at 11:47 pm
    SELECT g.Name,
           CASE WHEN p.group_id IS NOT NULL THEN 1 ELSE 0 END AS part_of_group
        FROM Groups g
            LEFT JOIN Permissions p
                ON g.id = p.group_id
                    AND p.user_id  = 60
        ORDER BY part_of_group DESC, g.Name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, I'm sorry if the title doesn't explain this very well. I'm looking
Let me first start off, sorry for the confusing title. I didn't know how
First off, sorry if this is a stupid question. I installed code::blocks to try
First off, sorry for the lame title, but I couldn't think of a better
Hey guys, first off all sorry, i can't login using my yahoo provider. anyways
First off, sorry if the title is confusing! I'm working on a part of
first of all sorry for the title. I know this is not so clear
First off, sorry for the cryptic question. My team is currently using Selenium 2.0rc3
First off, I am sorry if this is a duplicate, but every time I
First off, I'm rather n00b at AS3 so I'm sorry if this is a

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.