在MySQL中用IF条件更新... [英] Do update with IF condition... in MySQL

查看:505
本文介绍了在MySQL中用IF条件更新...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

如果且仅当我的

条件为真时,任何人都知道是否可以进行更新。

示例:


在MYTABLE中我有三列,如下:

ID(INT),PUBLISH(ENUM(Y,N) ),密码(VARCHAR(10))

这就是我想要做的事情:

用id = 333更新tablerow,SET publish =''是'如果密码='''xxx''


我正在尝试使用MySQL表达式IF(expr1,expr2,expr3)。但这个

真的不行!


如果可以在expr1中设置SELECT语句,它可以工作,

返回NULL或EmptyString。然后如果NULL DO(执行)expr2 ELSE

DO(执行)expr3


像这样:IF(SELECT * FROM mytable WHERE id = 333 AND

PASSWORD =''xxx'',UPDATE mytable SET publish =''N''WHERE id = 333,UPDATE

mytable SET publish =''Y''WHERE id = 333)


任何想法?

Hi!
Anyone knows if it''s possible to do an update if, and only if my
condition is TRUE.

Example:

In MYTABLE I have three columns, like this:
ID(INT), PUBLISH(ENUM(Y,N)), PASSWORD(VARCHAR(10))

This is what I want to do:
UPDATE the tablerow with id=333, SET publish=''Y'' IF password=''xxx''

I was trying out the MySQL-expression "IF(expr1,expr2,expr3)" but this
really doesn''t do it!

It could work if it was possible to set a SELECT statement in expr1,
returning NULL or EmptyString. Then if NULL DO(execute) expr2 ELSE
DO(execute) expr3

Like this: IF(SELECT * FROM mytable WHERE id=333 AND
PASSWORD=''xxx'',UPDATE mytable SET publish=''N'' WHERE id=333, UPDATE
mytable SET publish=''Y'' WHERE id=333 )

Any ideas?

推荐答案

JP写道:
J.P wrote:
这就是我想要做的事情:
用id = 333更新tablerow,SET发布=''Y''如果密码='''xxx''
This is what I want to do:
UPDATE the tablerow with id=333, SET publish=''Y'' IF password=''xxx''



#仅当密码和id匹配时才会更新行。

更新yourtablename set publish =''Y''其中id = 333且password =''xxx'';



# This will update row only if the password and id match.
update yourtablename set publish=''Y'' where id=333 and password=''xxx'';


JP写道:
J.P wrote:
这就是我想要做的:
用id = 333,SET更新tablerow publish =''Y''如果密码='''xxx''
This is what I want to do:
UPDATE the tablerow with id=333, SET publish=''Y'' IF password=''xxx''




#这将更新行o nly如果密码和id匹配。

更新yourtablename set publish =''Y'',其中id = 333,密码=''xxx'';



# This will update row only if the password and id match.
update yourtablename set publish=''Y'' where id=333 and password=''xxx'';


JP写道:
J.P wrote:
这就是我想要做的事情:
用id = 333更新tablerow,SET publish =''Y''IF password = ''xxx''
This is what I want to do:
UPDATE the tablerow with id=333, SET publish=''Y'' IF password=''xxx''




#只有在密码和id匹配时才会更新行。

update yourtablename set publish =''Y ''id = 333,密码=''xxx'';



# This will update row only if the password and id match.
update yourtablename set publish=''Y'' where id=333 and password=''xxx'';


这篇关于在MySQL中用IF条件更新...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆