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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:09:00+00:00 2026-06-15T15:09:00+00:00

I have user table and user_group table. A single user can be in multiple

  • 0

I have user table and user_group table. A single user can be in multiple group. I have two groups admin and user. Admin group has group id 1 and user group has group id 2. As I select from joining these two table. I would like to select it using join between two table:

select * from users u
join user_groups ug
on u.user_id = ug.user_id;

I get Admin two times in each row. I would like to eliminate other row for admin with group id as user i.e 1 in this query how can I achieve this? The sqlfiddle is here. Group related information is in all_groups table.

  • 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-15T15:09:01+00:00Added an answer on June 15, 2026 at 3:09 pm

    Assuming that you want to keep the row with the largest group_id value

    select *
      from (select u.user_id,
                   u.username,
                   u.first_name,
                   u.middle_name,
                   u.last_name,
                   u.password,
                   ug.group_id,
                   rank() over (partition by ug.user_id
                                    order by ug.group_id desc) rnk
              from users u
                   join user_groups ug
                     on u.user_id = ug.user_id)
     where rnk = 1;
    

    should work. Here is the sqlfiddle

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

Sidebar

Related Questions

I have two models, user and group. I also have a joining table groups_users.
I have a table like so: Table eventlog user | user_group | event_date |
I have a table with columns id, user I want to group by column
I created 3 tables: User User-Group Group Where I can have a many-to-many relationship.
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 ...
I have a single user table and I'm trying to come up with a
I have a user feed of image posts. Each user can post single images,
I have a function to get a single user from the database so I
Today i have new problem with JPA/EJB3. I have 2 table User and Group

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.