Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2011
    Posts
    16
    Thanks
    0
    Thanked 1 Time in 1 Post

    Help with joining multiple tables wanted

    Hey, for a tournament at my bar im making a little php application to keep track of contestors, score's etc... For this i have 3 tables wich i want to join and get data from each of the 3 table's.
    I first started my project with 2 table's and using INNER JOIN to get data from the 2 table's.

    I made a picture with some table's real quick to describe what i need.
    The column with orange border around it needs to be added in the query. It's located in my new table, gespeeld.




    There query i tryed to do is:

    Code:
    SELECT 
    	nietgespeeld.match_id, 
    	deelnemers.voornaam, 
    	deelnemers.familienaam,
    	gespeeld.deelnemer_score 
    FROM 
    	deelnemers,
    	gespeeld
    AS 
    	deelnemers inner join nietgespeeld 
    AS 
    	nietgespeeld 
    ON 	
    	deelnemers.deelnemer_id = nietgespeeld.deelnemer_id 
    AND
    	nietgespeeld.match_id = gespeeld.match_id
    i hope someone can help me out.
    Last edited by R-Mike; 04-14-2011 at 01:13 PM.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Don't mix different syntax styles of joining, that'll just confuse the issue. Join the three tables like this:

    Code:
    SELECT 
    	nietgespeeld.match_id, 
    	deelnemers.voornaam, 
    	deelnemers.familienaam,
    	gespeeld.deelnemer_score 
    FROM 
    	deelnemers AS deelnemers
    JOIN nietgespeeld AS nietgespeeld 
    ON 	
    	deelnemers.deelnemer_id = nietgespeeld.deelnemer_id 
    AND
    	nietgespeeld.match_id = gespeeld.match_id
    JOIN 	gespeeld AS gespeeld
    ON nietgespeeld.match_id = gespeeld.match_id
    AND nietgespeeld.deelnemer_id = gespeeld.match_id


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •