“Simple” SQL Query

前端 未结 5 1086
独厮守ぢ
独厮守ぢ 2020-12-20 02:58

Each of my clients can have many todo items and every todo item has a due date.

What would be the query for discovering the next undone todo item by due date for eac

5条回答
  •  心在旅途
    2020-12-20 03:26

    Some Jet SQL, I realize it is unlikely that the questioner is using Jet, however the reader may be.

    SELECT c.name, t.description, t.timestamp_due
    FROM (clients c 
          INNER JOIN 
             (SELECT t.client_id, Min(t.id) AS MinOfid
              FROM todos t
              WHERE t.timestamp_completed Is Null
              GROUP BY t.client_id) AS tm 
    ON c.id = tm.client_id) 
    INNER JOIN todos t ON tm.MinOfid = t.id
    

提交回复
热议问题