Got the query to work