Fixed non-standard SQL query