3
IF EXISTS (SELECT * FROM table1 WHERE group_id='8')
UPDATE table2 SET (...) 
WHERE usertype='numbereight'

我究竟做错了什么?我需要根据 group_id 更新用户类型

4

4 回答 4

1

试试这个:

UPDATE table2 
SET someColumn = 'somevalue'
WHERE EXISTS(SELECT * FROM table1 WHERE group_id='8')
AND usertype='numbereight'
于 2012-06-28T14:31:39.530 回答
1

你可以尝试这样的事情:

UPDATE table2
SET (...) 
WHERE usertype='number eight' AND EXIST(SELECT * FROM table1 WHERE group_id='8');
于 2012-06-28T14:36:21.000 回答
1

尝试

UPDATE table2 
SET (...) 
WHERE usertype = 'numbereight'
AND exists (select * from table1 where group_id = '8')
于 2012-06-28T14:37:22.987 回答
1

您可以加入表格并更新您需要的任何字段

UPDATE t1 JOIN t2 ON t1.id = t2.id
SET
  t2.field = 'whatever'
WHERE
  t1.group_id= '8' AND
  t2.usertype = 'numbereight'
于 2012-06-28T14:49:05.963 回答