Ted
Ted

Reputation: 3875

JOINING more then once?

I have a table of users:users
I have another table booths

  users
  ===============================  
  ID    |    NAME        |   SID
  -------------------------------
  1          cillia          abcd
  2          Ted             efgh

 booth
 =====================================================
  BOOTH_ID      |  BOOTH_OWNER    |     BOOTH_MANAGER  
 -----------------------------------------------------
   1               1                    2
   2               2                    4
   3               1                    3

I would like to create a query that would make clear for a specific booth, the name of the manager and the name of the owner.
What is the best approach to do that?

Upvotes: 1

Views: 42

Answers (1)

Linger
Linger

Reputation: 15048

You would just link the users table to the booth table twice:

SELECT b.BOOTH_ID, s1.NAME AS BoothOwner, s2.NAME AS BoothManager
FROM booth b
INNER JOIN users s1 ON b.BOOTH_OWNER = s1.ID
INNER JOIN users s2 ON b.BOOTH_MANAGER = s2.ID

Upvotes: 3

Related Questions