query.c: Fixed logic of ≤ operator

The code was also modified to reduce duplication.

Signed-off-by: Morten Hustveit <morten.hustveit@gmail.com>