Reputation:
I have a database with one table, let's say 'tablename'. Now, I want the first column of that table, named 'text' to be updated with the text it containts PLUS some new text which comes as result from another query executed over 'tablename2'. So, I want something like this:
UPDATE tablename SET text="current text" + (SELECT * FROM tablename2 where ID=12);
If 'text' value is 'Result not available
' I want to append ' here
', so that the field value is 'Result not available here
'
How is this possible? Thanks
Upvotes: 0
Views: 945
Reputation: 14596
I probably misunderstood your question, but let's try:
http://sqlfiddle.com/#!5/959e5/2
UPDATE Table1
SET text = text ||
CASE
WHEN text = 'Result not available' THEN ' here'
ELSE (SELECT text FROM Table2 where id = 12)
END;
Upvotes: 1
Reputation: 3249
Try the concatenation operator (||):
UPDATE tablename SET text='current text'||(SELECT * FROM tablename2 where ID=12);
And I'm not sure, but you should use ' instead of " .
Upvotes: 1