r/SQL • SQeeLer😁 • May 05 '26

MySQL Forward filling of missing values through variables in MySQL

Hey folks!

While practicing MySQL last year, I came across the forward filling problem whereby you've to replace each NULL value in a column by the latest non-NULL value in that column.

For instance, a table ffill is as follows:

Table is 'ffill' with 6 records

The expected output is as below:

As we can see, the NULL values in dept column are forward filled. Here is the MySQL query I wrote back then to yield the output table above:

My question is, are there caveats of forward filling like this? What might they be? Will this way always work across the DBMSes? What would be the implications of this approach on large data sets?

5 Upvotes

3 comments sorted by

View all comments

Show parent comment

1

u/tlefst SQeeLer😁 May 05 '26

Ah I see.🤔
I do have other SQL queries to effect the forward filling, of course.
It was this 'variables approach' I was wondering about.
Thanks for your inputs.✌