select from and update into the same table
I have table (TEST) with columns (tid, title, subject). I need to select first 30 chars of (subject) and update it in to its (title) column as follows. When I tried the following, it says SQL command not properly开发者_开发技巧 ended. Any idea?
update a set a.title = substr(b.subject, 0, 30) from trkowner.test a join trkowner.test b on a.tid = b.tid;
You don't need join in this case. Just perform:
update trkowner.test set title = substr(subject, 0, 30)
精彩评论