samedi 2 juillet 2016

Getting all relevant data from a double join in MySQL?

So I have a rather simple query:

SELECT matches.*
FROM matches
    LEFT JOIN results AS p1
        ON (p1.extra = matches.player1_id AND p1.event_id = matches.event_id)
    LEFT JOIN results AS p2
        ON (p2.extra = matches.player2_id AND p2.event_id = matches.event_id)
WHERE matches.event_id = ?

This query gets all the matches in an event, and links player1 and player2 to their corresponding row in the results table.

The problem I am having is in differentiating the data from the two results joins. Each result row has about 20 pieces of data in it. So if I had to select all 40 pieces of data in this query, thats quite a few aliases to add to the SELECT field.

Is there an easier way to do this? Possibly store the two rows into an array so I can access them later?

Aucun commentaire:

Enregistrer un commentaire