Sample table below. I recently added the column 'is_last_child' and want to update it to have a value 1 if the row is the last child (or is not a parent). I had a query of
update node set is_last_child=1 where id not in (select parent_id from node);
I get the following error when I run it. "You can't specify target table 'node' for update in FROM clause". I've tried using a join, but I'm sure how exactly I can update only the rows that are not a parent. Any one have any ideas or have run into a similar situation?
id | parent_id | is_last_child
1 | 1 | 0
2 | 1 | 0
3 | 1 | 0
4 | 2 | 0
5 | 4 | 0
6 | 1 | 0
Essentially I want to select ids 3, 5, and 6 and set the column is_last_child equal to 1. This isn't my schema and there are thousands of rows, but the table above is just to simplify things.