Got the query working