Phoenix - 6 months ago 29

SQL Question

I was working on a query today which required me to use the following to find all odd number ID values

`(ID % 2) <> 0`

Can anyone tell me what this is doing? It worked, which is great, but I'd like to know why.

Answer

`ID % 2`

is checking what the remainder is if you divide ID by 2. If you divide an even number by 2 it will always have a remainder of 0. Any other number (odd) will result in a non-zero value. Which is what is checking for.