Query the database