I have this MYSQL table (simplified version) with some erased ids:
+-----+-------+---------+
| id | name | country |
+-----+-------+---------+
| 1 | John | England |
| 5 | Emily | USA |
| 9 | Joe | USA |
| 11 |Michael| USA |
| 13 | Liam | USA |
+-----+-------+---------+
How do I overwrite each row from "John" using php? (last name "Liam" gets kicked out)
I want it to look like this:
+-----+-------+---------+
| id | name | country |
+-----+-------+---------+
| 1 | John | England |
| 5 | John | USA |
| 9 | Emily | USA |
| 11 | Joe | USA |
| 13 |Michael| USA |
+-----+-------+---------+
2
Answers
I understand that you want to copy each name on the "next" row.
If you are running MySQL 8.0, you can do this with a self join and window functions:
You can use correlated query as follows: