Update sql with 2 conditions

Asked

Viewed 4,011 times

1

I have a table with the column STATURE
This column consists of 3 possible values: NEW, VISUALIZED, DISCARDED

I have a function where I need to implement an SQL row that updates my table and changes all the values in the column STATURE to: DISCARDED

The logic is:

Update in: minhatabela, the column: statuz - where the value NEW for DISCARDED is, and where the value VISUALIZED for DISCARDED is. (at once)

the command I’m using, but it has no effect is:

 UPDATE toyota_base SET statuz = 'DESCARTADO' WHERE statuz = 'NOVO' and statuz = 'VISUALIZADO';

All help is welcome. Thank you.

1 answer

6


statuz has only one value, so it nay can be at the same time NOVO and VISUALIZADO so update does not change any record.

Exchange the AND (conjunction) by OR (disjunction)

UPDATE toyota_base SET
   statuz = 'DESCARTADO'
WHERE statuz = 'NOVO' or statuz = 'VISUALIZADO';

Or use the IN() clasp that will have the same effect.

UPDATE toyota_base SET
   statuz = 'DESCARTADO'
WHERE statuz IN('NOVO','VISUALIZADO');
  • Oops, thank you very much, that’s right...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.