Clean a sql query