2

Looked up of all questions about error with minus operator in MYSQL and can't find solution. all given solutions not working. i`m trying to get difference between Units In Stock and Units On Order and my query like this:

$sql = "SELECT   UnitsInStock - UnitsOnOrder as 'Difference'
        FROM products ";

why i got this error?

 Warning: mysqli_query(): (22003/1690): BIGINT UNSIGNED value is out of range
Victorino
  • 1,623
  • 11
  • 22
  • What are the values of `UnitsInStock` and `UnitsOnOrder` which generate this error? It sounds like the subtraction is overflowing the unsigned numeric value. (Perhaps producing a negative value?) – David Jan 17 '14 at 22:55
  • yes it producing a negative value to – Victorino Jan 17 '14 at 22:58
  • 3
    I don't understand why people find it so difficult to put their error message into the SO search box? That almost always finds questions with answers. Do you really think you're the first one to get this error? – Barmar Jan 17 '14 at 22:58

1 Answers1

3

You can try this one:

SELECT CAST(UnitsInStock AS SIGNED) - CAST(UnitsOnOrder AS SIGNED) as 'Difference' FROM products
Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480