SQL query problem: MySQL

advertisements

The following query returns null in MySQL. I check all things like cos, acos individually. But this query is returning NULL. Kindly help me. altitude and latitude is the geo location of the places

select
acos(sin(74.338372290294) * sin(altitude) +
        cos(74.338372290294) * cos(altitude) *
        cos(latitude) - (31.552278760192)) as omg
from shk_resturants


If any of the values in your table (latitude or altitude) are NULL, the result may be NULL also. Try to use the function

COALESCE(value, ...)

e.g.

select
  acos(sin(74.338372290294) * sin(COALESCE(altitude, 0)) +
  cos(74.338372290294) * cos(COALESCE(altitude, 0)) *
  cos(COALESCE(latitude, 0)) - (31.552278760192)) as omg
from shk_resturants

This returns 0 for the columns, that have NULL-values.

See: MySQL Comparsion-Operators and: MySQL Math-Functions