0

how to get previous column value in mysql?

i have 1 table like this

=====================
=== id  ===  name ===
=====================
===  1  ===  Foo1 ===
===  2  ===  Foo2 ===
===  3  ===  Foo3 ===
=====================

what i expected like this

=====================================================
=== id  ===  name === previous_name_column_value ====
=====================================================
===  1  ===  Foo1 ===          null              ====
===  2  ===  Foo2 ===          Foo1              ====
===  3  ===  Foo3 ===          Foo2              ====
=====================================================

how to do that? anyone please help me..

  • [LAG() function](https://dev.mysql.com/doc/refman/8.0/en/window-function-descriptions.html#function_lag) – Akina Feb 21 '23 at 12:05
  • If not on MySQL 8.0 the answer is already available on [SO](https://stackoverflow.com/questions/11303532/simulate-lag-function-in-mysql/11316349#11316349) – mrrobot.viewsource Feb 21 '23 at 12:21

0 Answers0