简体   繁体   English

从同一表中选择两行

[英]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语句:

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. 我希望从t_people表中提取两个人。

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 编辑正如你可以看到在上面,我一个提取与使用m_table.red_id的,我希望选择与使用m_table.blue_id 编辑的另一行

How should approach this? 应该如何处理?

Just add another JOIN with another alias 只需添加另一个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

And then select values from it using this aliases, eg. 然后使用该别名从中选择值,例如。 people1.name . people1.name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM