changed query to be compatible with mysql 4.4