Fixes query for mysql