I have the following table.
id | user_id | file_id | completed | updated |
---|---|---|---|---|
1 | 161 | 10 | 1 | 2022-10-11 |
2 | 164 | 11 | 1 | 2022-10-12 |
3 | 161 | 10 | 1 | 2022-10-12 |
4 | 167 | 10 | 1 | 2022-10-10 |
5 | 167 | 10 | 1 | 2022-10-11 |
6 | 167 | 10 | 1 | 2022-10-12 |
I want to select the row for each user having the max updated
date for each file_id
.
SELECT * FROM user_file
WHERE updated = (SELECT uf.updated FROM user_file uf GROUP BY uf.user_id,uf.file_id)
I have come up with this query but it returns an error "Subquery returns more than 1 row"