Group by entity ID to prevent duplication

This will prevent duplication on the zariz_query_alter()