0

) 我希望在一堆连接的顶部从同一个表中选择两行,但我不确定到底该怎么做。这是我当前的选择语句:

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 选择另一

应该如何处理?

4

1 回答 1

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.

于 2013-10-18T16:02:41.520 回答