# MySQl query

**URL:** <https://forum.kirupa.com/t/mysql-query/187847>\
**Category:** programming\
**Created:** [May 2, 2006, 7:00pm UTC](https://forum.kirupa.com/t/mysql-query/187847 "2006-05-02T19:00:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimjiminyjimjim](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@jimjiminyjimjim](https://forum.kirupa.com/u/jimjiminyjimjim)\
**Post date:** [May 2, 2006, 7:00pm UTC](https://forum.kirupa.com/t/mysql-query/187847/1 "2006-05-02T19:00:27Z")

</div>

I have this query at the moment that subtracts 1 from the total of a field called total votes.

What I really need it to do is stop subtracting one when totalvotes gets to 0 so that this value never goes into the negative.

```php

$query = "UPDATE brands SET totalvotes=totalvotes-1 WHERE company = '" . $row['company'] . "'"; 

```
