Question: I have this query

```
UPDATE table SET this = this-20 WHERE this >= 0

```

i dont want `this` field to ever go under 0. Is there some addition I can add to this query to ensure this, without having to run another query?

eg, if this was 18, then it would be set to -2

(USING MYSQL)

Answer: 
You can make use of the *Greatest* function:

```
UPDATE table SET this = greatest(0,this-20) WHERE this >= 0

```

that basically set the value of this with the bigger value considering **this - 20** and **0**.
Change your condition to `WHERE (this - 20) >= 0`. 
And create a check constraint: `ALTER TABLE [table] ADD CONSTRAINT ThisGreaterThanZero CHECK (this >= 0)`.