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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:28:03+00:00 2026-05-20T11:28:03+00:00

I have many tables that represent groups that can be participated in (let’s say

  • 0

I have many tables that represent groups that can be “participated” in (let’s say Clubs, Societies, and Classes), and a table representing all “participations” (Participations). Therefore, I can find out what classes a user is participating in as follows:

SELECT * FROM Participations WHERE user_id = 1 and Participations.group_type = "Class";

I could also find out which users are in the club with the id 12 by doing something like this:

SELECT * FROM Users INNER JOIN Participations ON (Users.id = Participations.user_id) WHERE Participations.group_type = "Club" and Participations.group_id = 12;

I WANT to find all of the users who are in Club 12, or Club 20, or Class 10, without returning any users who are not participating in any of these groups.

SELECT * FROM Users INNER JOIN Participations ON (Users.id = Participations.user_id) WHERE (Participations.group_type = "Club" AND Participations.group_id IS IN (12,20)) OR (Participations.group_type = "Class" AND Participations.group_id IS 10)

And furthermore, I want to display the name of the group they participated in, again without including any users who are not participating in any of these groups (something like this):

SELECT Users.*, Classes.name, Clubs.name, FROM Users, Classes, Clubs, Participations (Users.id = Participations.user_id) WHERE Users.id = Participations.user_id AND ((Participations.group_type = "Club" AND Participations.group_id IS IN (12,20)) OR (Participations.group_type = "Class" AND Participations.group_id IS 10))

But I would prefer to use explicit joins. Is it doable?

  • 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-20T11:28:04+00:00Added an answer on May 20, 2026 at 11:28 am

    You can just add required conditions to the join clause:

    SELECT * FROM Users 
     INNER JOIN Participations 
        ON (Users.id = Participations.user_id) 
       AND ( (Participations.group_type = "Club" AND Participations.group_id IS IN (12,20)) 
          OR (Participations.group_type = "Class" AND Participations.group_id IS 10) )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a star schema type data base, with fact tables that have many
I have two tables that are joined together. A has many B Normally you
I have the following tables in my database that have a many-to-many relationship, which
I have a table that has 8 million records, with many fields, including lat/long
I have a rather large (many gigabytes) table of data in SQL Server that
Many applications have grids that display data from a database table one page at
Right now I have a table called Campaigns that has many Hits, if I
I have many tables in my database which are interrelated. I have a table
I have database with many tables. In the first table, I have a field
I have a scenario where: there are two (or more) tables that represent independent

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.