我正在尝试使用最新的时间戳返回带有与其链接的注释的任务。尽管此查询有效,但它并未一致地返回最新的时间戳。还有另一种方法吗?
SELECT DISTINCT tasks.TaskID, tasks.desc, tasks.startdate, tasks.active, notes.note, max(notes.NoteDate)
FROM tasks INNER JOIN notes ON tasks.TaskID=notes.NoteID
WHERE notes.NoteDate >= curdate()
GROUP BY tasks.TaskID
答案 0 :(得分:0)
尝试以下方面的内容:
SELECT tasks.TaskID, tasks.desc, tasks.startdate, tasks.active, notes.note, notes.NoteDate
FROM tasks INNER JOIN notes ON tasks.TaskID=notes.NoteID
order by NoteDate Desc
limit 1
更新,如果您想要多行(例如在上一天注明):
SELECT tasks.TaskID, tasks.desc, tasks.startdate, tasks.active, notes.note, notes.NoteDate
FROM tasks INNER JOIN notes ON tasks.TaskID=notes.NoteID
where notes.NoteDate > date_sub(current_date(),interval 1 day)
order by NoteDate Desc