Fixing query to database.