Mathias
Mathias

Reputation: 119

Selecting two rows from the same table

) I wish to select two rows from the same table ontop of a bunch of joins, but i'm not sure what exactly to do. This is my current select statement:

SELECT m_table.*, t_people.name as boxer_name, t_people.class, t_people.age, t_people.sex, m_time.time, m_time.rounds, t_age.name as age_name, teams.name as team_name
FROM m_table
INNER JOIN t_people ON t_people.id = m_table.red_id
INNER JOIN m_time ON (m_time.age = t_people.age AND m_time.sex = t_people.sex OR m_time.age = t_people.age AND m_time.sex = 'u')
INNER JOIN t_age ON t_age.id = t_people.age
INNER JOIN teams ON teams.id = t_people.team_id

I wish to extract two people from the t_people table.

EDIT As you can see above i'm extracting one with the use of m_table.red_id And i wish to select another row with the use of m_table.blue_id EDIT

How should approach this?

Upvotes: 0

Views: 1145

Answers (1)

Elon Than
Elon Than

Reputation: 9765

Just add another JOIN with another alias

INNER JOIN t_people people1 ON people1.id = m_table.red_id
INNER JOIN t_people people2 ON people2.id = m_table.blue_id

And then select values from it using this aliases, eg. people1.name.

Upvotes: 2

Related Questions