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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:42:31+00:00 2026-05-25T10:42:31+00:00

I have 4 tables : one with events , one with those events’ attendants

  • 0

I have 4 tables : one with events, one with those events’ attendants, and two others containing information about those attendants, might they be single persons or groups of persons. The design of the database seems fair, right ?

I then need to get the name of who is going to attend a particular event. I’ll then get the type of the event’s attendants, and its id using a regular join. But i also need attendants’ names, and its stored in two different tables depending on what type the attendant is.

Have a look at what i did :

SELECT
    ep.type_attendant 'type',
    ep.id_attendant 'id',
    IF( ep.type_attendant = 'user', CONCAT( u.firstname, ' ', u.lastname ), g.name ) 'fullname'
FROM
    events_attendants ep,
    events e,
    users u,
    groups g
WHERE
    ep.id_event = e.id AND
    ep.id_attendant = IF( ep.type_attendant = 'user', u.id, g.id )

That works, but is not perfect since it returns duplicate rows for the table groups.
What i’d like to end up with is something like that : (except the one below doesn’t work)

SELECT
    ep.type_attendant 'type',
    ep.id_attendant 'id',
    IF( ep.type_attendant = 'user', CONCAT( u.firstname, ' ', u.lastname ), g.name ) 'fullname'
FROM
    events_attendants ep,
    events e,
    IF( ep.type_attendant = 'user', users u, groups g ) -- variable table
WHERE
    ep.id_event = e.id AND
    ep.id_attendant = IF( ep.type_attendant = 'user', u.id, g.id )

I could also run two queries, and merge their results with PHP, but i’m the kind of guy who likes to learn.

MySQL database btw. Thanks for your help!

  • 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-25T10:42:32+00:00Added an answer on May 25, 2026 at 10:42 am
        SELECT
            ep.type_attendant AS `type`,
            ep.id_attendant   AS id,
            CONCAT( u.firstname, ' ', u.lastname ) AS fullname
        FROM
            events_attendants ep
          JOIN
            events e    ON ep.id_event = e.id 
          JOIN
            users u     ON ep.id_attendant = u.id
        WHERE
            ep.type_attendant = 'user'
    UNION ALL
        SELECT
            ep.type_attendant,
            ep.id_attendant,
            g.name  
        FROM
            events_attendants ep
          JOIN
            events e    ON ep.id_event = e.id 
          JOIN
            groups g    ON ep.id_attendant = g.id
        WHERE
            ep.type_attendant <> 'user'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 tables. In one table I add events, ID are auto-increment. The
I have 2 tables - one storing user information (id, username, password) and the
I have two tables : one table it matchs and the other is teams.
I have used a join query for retrieving value from two tables one is
I have two tables, one for routes and one for airports. Routes contains just
I have ten master tables and one Transaction table. In my transaction table (it
I have some tables. These tables all have one column in common called 'classified_id':
I have an edmx model which I have draged 2 tables onto - One
I have 2 tables that their rows have one on one relation.. For you
I have SMO code which copies tables from one database to another. It runs

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.