Build a valid query