Corrected query that prevented referencing entities to be properly selected