I have two columns in my table, and I am trying to update the second column with the result of first col like this.
SET @pg = (SELECT ID FROM wp_posts WHERE post_name = 'y' AND post_status = 'x' LIMIT 1)
Now the above query works the (SELECT ...) as in it returns an ID from the query, so I am trying to use that ID to update another column like this.
UPDATE wp_posts SET post_type = 'foo' WHERE ID = @pg;
But for some reason the above does not work.
and I get the following error.
1 queries executed, 0 success, 1 errors, 0 warnings
Query: set @pg = (SELECT ID FROM wp_posts WHERE post_name = 'y' AND post_status = 'x' LIMIT 1) SELECT * ...
Error Code: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT * FROM wp_posts WHERE id = @pg' at line 3
Execution Time : 0 sec
Transfer Time : 0 sec
Total Time : 0 sec
EDIT/UPDATE:
I am also trying to execute this staetment, which is simpler and does the same thing
UPDATE wp_posts SET post_type = 'x' WHERE ID = (SELECT ID FROM wp_posts WHERE post_name = 'y' AND post_status = 'z' LIMIT 1)
but for some reason, it doesn't work.