Fix derby queries