Fixed groupByPk Logic