user4591549
user4591549

Reputation:

sql: how can I find a value and replace it simultaneously?

How can I do something like that

SELECT * WHERE owner = '81',

    owner = NULL

FROM outcome

or

UPDATE outcome SET NULL WHERE owner = '81'

So before request the table contains values 81 but after request corresponding values in NULL.

Upvotes: 2

Views: 57

Answers (2)

SoulTrain
SoulTrain

Reputation: 1904

Is this what you want?

SELECT * FROM OUTCOME WHERE (OWNER IS NULL OR OWNER='81')

UPDATE outcome SET owner=NULL 
WHERE owner = '81'

Upvotes: 1

peter.petrov
peter.petrov

Reputation: 39457

Assuming outcome is your table name, here is what you need:

UPDATE outcome 
SET owner = NULL 
WHERE owner = '81'

If you also want to select the updated rows see here:

OUTPUT Clause in MySQL

So... in MySQL that part seems a bit tricky.

Upvotes: 1

Related Questions