簡體   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