MySQL - 如果表 A 左连接到表 B,我如何按表 B 中的字段进行排序?
这是我的 SQL 查询:
SELECT pts.pts_id,
pts.pts_name,
meds.*
FROM pts
LEFT JOIN meds
ON pts.pts_id = meds.pts_id_fk
WHERE pts.id_fk = $id
AND pts_current = 1
表pts
(即表 A)具有以下数据:
pts_id time
1 Joe
2 Jack
3 Jill
表meds
(即表 B)具有以下数据:
pts_id_fk time
1 7AM
1 8AM
1 9AM
2 7AM
2 10AM
3 11AM
我想ORDER BY
此查询的结果基于时间
。
有什么建议如何做到这一点?
Here is my SQL query:
SELECT pts.pts_id,
pts.pts_name,
meds.*
FROM pts
LEFT JOIN meds
ON pts.pts_id = meds.pts_id_fk
WHERE pts.id_fk = $id
AND pts_current = 1
Table pts
(ie Table A) has the following data:
pts_id time
1 Joe
2 Jack
3 Jill
Table meds
(ie Table B) has the following data:
pts_id_fk time
1 7AM
1 8AM
1 9AM
2 7AM
2 10AM
3 11AM
I would like to ORDER BY
the result of this query based on the time
.
Any suggestions how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,
ORDER BY meds.time
怎么样?Uhm what about
ORDER BY meds.time