How do I set only one column row in which all values in this column are the same?

1

I'm trying to set the column ocupado only one line at a time, something like:

update suite set ocupado = 'S' where tipo = 'i';

But this statement changes all rows in column ocupado where tipo is i , and that's not what I want. I want only a single line between these to be changed to "S", the others that meet the condition should remain unchanged.

It is a reservation system, no matter which line is changed, but it should only be one that meets the above conditions. In the next execution of this query it will do with another line because it stops fulfilling the condition.

+--+-----+--------+
|id|tipo |ocupado |
+-----------------+
|01| i   | N      | <- alteraria só esta 
|02| i   | N      |
|03| c   | N      |
|04| c   | N      |
+-----------------+
    
asked by anonymous 24.10.2018 / 17:36

1 answer

0

Putting faith in what you explained in the comments would be this:

update suite set ocupado = 'S' where tipo = 'i' and ocupado <> 'S' limit 1;

So you make sure you do only one line at a time, always if the type is selected and not where you already have a N .

    
24.10.2018 / 19:06