Suppose I have the next table structure, table A:
| id |
|----|
| 3 |
| 4 |
| 7 |
Table B:
| id | title | last_id |
|----|-------|---------|
| 1 | a | 1 |
| 2 | b | 2 |
| 3 | c | 3 |
I want to change Table’s B last_id to the next matching id from Table A.
Example: (Referring to Table’s B first row)
Current last_id is 1, So I need to forward it’s value to the next, bigger id from Table A.
So it will go:
1 -> 3 -> 4 -> 7
It can be done also with PHP, but maybe there is a way to keep it in the SQL Server.
Thanks in advance.
NOTE: The server runs MySQL.
Previous answer is correct, but the +1 I believe is no needed as you just need value 7
Edited:
Now it picks the minimum value from table_a bigger that the last_id on table_b