Reputation: 31
IF EXISTS (SELECT * FROM table1 WHERE group_id='8')
UPDATE table2 SET (...)
WHERE usertype='numbereight'
what am i doing wrong? I need to update the usertype based on the group_id
Upvotes: 3
Views: 175
Reputation: 918
You can join the tables and update whatever fields you need
UPDATE t1 JOIN t2 ON t1.id = t2.id
SET
t2.field = 'whatever'
WHERE
t1.group_id= '8' AND
t2.usertype = 'numbereight'
Upvotes: 1
Reputation: 79979
Try this instead:
UPDATE table2
SET someColumn = 'somevalue'
WHERE EXISTS(SELECT * FROM table1 WHERE group_id='8')
AND usertype='numbereight'
Upvotes: 1
Reputation: 2772
Try
UPDATE table2
SET (...)
WHERE usertype = 'numbereight'
AND exists (select * from table1 where group_id = '8')
Upvotes: 1
Reputation: 72696
You can try with something like this :
UPDATE table2
SET (...)
WHERE usertype='number eight' AND EXIST(SELECT * FROM table1 WHERE group_id='8');
Upvotes: 1