假设我有两个表,用户和注释。假设架构如下所示:
users
id, name, field2, field3
notes
id, user_id, subject, heading, body, timestamp
我想要做的是选择每个用户,以及每个用户根据时间戳发布的最新(仅 1)条注释,以显示在概览报告中。
我该怎么做呢?请注意,数据库是 MySQL。
Thanks!
select users.name, notes.subject, notes.heading, notes.body
from users, notes
where users.id = notes.user_id
and notes.timestamp = (select max(timestamp) from notes where user_id = users.id)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)