Small fix to a query that could crash to server

I really need to test EVERYTHING before I push it...