Changed custom query to comply with MySQL standards.