Reputation: 131
i have the following table
id | name | flag |
---|---|---|
1 | carl | 0 |
2 | mark | 1 |
3 | steve | 1 |
what I want to do is the first row would override the succeeding row value for flag so the result would be something like this
id | name | new_inherited_flag | original_flag |
---|---|---|---|
1 | carl | 0 | 0 |
2 | mark | 0 | 1 |
3 | steve | 0 | 1 |
how do i achieve this?
Upvotes: 0
Views: 50
Reputation: 522094
You could just use a subquery to find the earliest flag
value:
SELECT id, name,
(SELECT flag FROM yourTable ORDER BY id LIMIT 1) AS new_inherited_flag,
flag AS original_flag
FROM yourTable
ORDER BY id;
Upvotes: 1