我正在尝试使用此查询显示一个时间列表:
SELECT `account_id`, `finish_time` FROM `race_times` WHERE `race_id` = %i ORDER BY `finish_time` ASC LIMIT 10
它将返回字段'account_id' ,但'account_name'可以由用户更改,并存储在表'用户'中,该表还具有自动增量的原始account_id值。
当表'race_times'中只有'account_id'值时,是否可以使上面的查询从表'用户'返回'account_name'?
答案 0 :(得分:0)
SELECT rt.account_id, rt.finish_time, u.account_name
FROM race_times AS rt
INNER JOIN users AS u ON tr.account_id = u.account_id
WHERE race_id = %i
ORDER BY finish_time ASC
LIMIT 10;
答案 1 :(得分:-1)
SELECT `account_id`, `finish_time`,account_name FROM `race_times`,users WHERE `race_id` = %i and users.account_id=race_times.account_id ORDER BY `finish_time` ASC LIMIT 10
答案 2 :(得分:-1)
您可以使用内部联接或只使用查询中的两个表
从race_time选择u.account_name,rt.account_id,rt.finish_time为rt,用户为u,其中u.account_id = rt.account_id和rt.race_id =%i