繁体   English   中英

从另一个表中选择最近的行

[英]Select most recent row from another table

我想显示不同表中的最新评论及其日期。 不同的表键控到主表中的行。 换一种说法:

“主”表键控到notes表。 notes表可以有任意数量的条目,提供参考main表行所采取的步骤的详细信息,但我只想在我的查询中显示最近的评论和日期。

主表名是表notes. The 2 columns in mainnotes. The 2 columns in I need are笔记中notes. The 2 columns in I need are entry_timestamp and activity_notes`。

就像是

select
  (select activity_notes from notes n where n.mainId = m.id order by m.entry_timestamp desc LIMIT 1)
  , (select entry_timestamp from notes n where n.mainId = m.id order by m.entry_timestamp desc LIMIT 1)
from main m

暂无
暂无

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

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