Please help me with MySQL update to update the column with result returns from select itself.
For instance, I have two tables
TABLE user( userid int, groupid int )
TABLE thread ( threadid int, userid int, sticky tinyint, vip tinyint )
Now I'm trying to achieve this with a single update query, but can't seem to do it. What I thought I should do is:
UPDATE user SET groupid=15 WHERE userid IN (SELECT userid FROM thread t LEFT JOIN user u ON u.userid=t.userid WHERE (t.sticky=1 AND t.vip=1) AND (u.groupid=11 OR u.groupid=14) GROUP BY t.userid);
but MySQL saids: #1093 - You can't specify target table 'user' for update in FROM clause
Please help me!