I have a table called table_1 with all the history of some users as you can see here for the day 2022-03-02:
+-----------+-------------+----------+------------+-----+
| ID | Name | Document | Date | opt |
+-----------+-------------+----------+------------+-----+
| 1a | Albert | 11111111 | 2022-03-02 | xxx |
| 2a | Dani | 22222222 | 2022-03-02 | xxx |
+-----------+-------------+----------+------------+-----+
The next day I have the same thing but with a change in the document:
+-----------+----------+----------+------------+-----+
| ID | Name | Document | Date | opt |
+-----------+----------+----------+------------+-----+
| 1a | Albert | 11111111 | 2022-03-02 | xxx |
| 2a | Dani | 22222222 | 2022-03-02 | xxx |
| 1a | Albert | 55555555 | 2022-03-03 | xxx |
| 2a | Dani | 22222222 | 2022-03-03 | xxx |
+-----------+----------+----------+------------+-----+
As you can see there is a change in the Document column on the day 2022-03-03. What I want to do is get this information in a new table with the rows that have changes, in this case it would be like this:
+-----------+---------+----------+------------+----------+------+
| ID | Name | Document | Date | new_doc | opt |
+-----------+---------+----------+------------+----------+------+
| 1a | Albert | 11111111 | 2022-03-02 | 55555555 | xxx |
+-----------+---------+----------+------------+----------+------+
I'm trying to do this with subqueries, but I can't find a way to compare the data for the day specified in Date with the day before.
How could I do this? Thanks in advance!