Difficult JOIN?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    Difficult JOIN?

    I have a difficult join situation which I am not quite sure on the SYNTAX or if it's even possible:
    Code:
    $raw_alliance_info = mysql_query( 	"SELECT name, code, description, members, focus, bonus,
    									leader, sub, officer1, officer2, officer3
    									FROM alliances WHERE id='$alliance_id'");
    This basically gets info from my "alliances table" but the problem is the leader, sub, officer1, officer2, officer3 columns.
    These columns contain the user id who is in the role at the time. I want to get the user name for each by joining this table somehow with my users table (which contains each user's name).
    Can it be done, or do I have to store usernames in the alliances table as well as their id's?
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    It looks possible but I may not fully understand. Something like
    SELECT name, code, description, members, focus, bonus,
    leader, sub, officer1, officer2, officer3
    FROM alliances
    JOIN users ON(`alliances`. `leader` = `users`.`leader `
    OR alliances`.`sub ` = `users`.`sub`
    OR alliances`.`off icer1` = `users`.`office r1`
    OR alliances`.`off icer2` = `users`.`office r2`
    OR alliances`.`off icer3 ` = `users`.`office r3`)
    WHERE id='$alliance_i d'

    Comment

    • TheServant
      Recognized Expert Top Contributor
      • Feb 2008
      • 1168

      #3
      Thanks for your reply. I will give it a go when I get home, but I have a feeling it is not really what I am after because it should really be ANDs nor ORs, but I don't think that will work. Maybe I let this one go and just double up a bit on data for simplcity sake.

      Comment

      Working...