'Convert SQL query to QueryBuilder
I am trying to convert this query to the querybuilder: provide the last record of each day
SELECT a.id, a.updated, a.sessionId
FROM SortingSessionSave a
INNER JOIN
(
SELECT DATE(updated) AS updated_date, MAX(updated) AS max_updated, sessionId
FROM SortingSessionSave
WHERE DATEDIFF(NOW(), DATE(updated)) > 10
GROUP BY DATE(updated) , sessionId
) b
ON b.updated_date = DATE(a.updated) AND
b.max_updated = a.updated
ORDER BY
a.updated;
I need the last updated(saved) record from all records older than 10 days. Do I use a subquery, or will I be able to state the subquery in the where clause?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
