从同一个表中选择两行

时间:2013-10-18 15:59:11

标签: mysql sql

) 我希望从一堆连接的同一个表中选择两行,但我不确定究竟要做什么。 这是我目前的选择声明:

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

我希望从t_people表中提取两个人。

修改的 如上所示,我使用m_table.red_id提取一个 我希望使用m_table.blue_id选择另一行 修改

应如何处理?

1 个答案:

答案 0 :(得分:1)

只需添加另一个JOIN另一个别名

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

然后使用此别名从中选择值,例如。 people1.name