I have this query, which selects data from one of the previous row's columns ('next_line'), and data from a different column in the most recent row ('raw_line').
SELECT CONCAT((SELECT `next_line` FROM `lines` ORDER BY id DESC LIMIT 1 OFFSET 1), (SELECT
`raw_line` FROM `lines` ORDER BY id DESC LIMIT 1))
This query works perfectly as it is. But what I want to do is put this output into a different column in the most recent row *('composed_line')*. But when I do this:
UPDATE `lines` set `composed_line`=CONCAT((SELECT `next_line` FROM `lines` ORDER BY id DESC LIMIT
1 OFFSET 1), (SELECT `raw_line` FROM `lines` ORDER BY id DESC LIMIT 1)) ORDER BY id DESC LIMIT 1;
I get this error:
#1093 - You can't specify target table 'lines' for update in FROM clause
So I tried this:
UPDATE `lines` set `composed_line`=CONCAT((SELECT `next_line` FROM (SELECT * FROM `lines` ORDER
BY id DESC LIMIT 1 OFFSET 1) AS `alias`, (SELECT `raw_line` FROM (SELECT * FROM `lines` ORDER BY
id DESC LIMIT 1)) AS `alias2` ORDER BY id DESC LIMIT 1
And I got this error:
#1248 - Every derived table must have its own alias
I can't see what I am doing wrong - do 'alias' and 'alias2' not count as derived table aliases?
Any help is so much appreciated!