Yii php :删除数据库中的重复项并更新重复行


Yii php : Remove duplicates in the database and update the duplicate row

我正在使用Yii php,我在数据库中遇到重复条目的问题。

为了演示,假设我有这个:

id(pk) | parent_id | parent_name| is_male(boolean) | is_female(boolean)
------------------------------------------------------------------------
1      |     1     |parent1     | true             | false                
------------------------------------------------------------------------
2      |     1     |parent1     | false            | true
------------------------------------------------------------------------
3      |     2     |parent2     | false            | true
------------------------------------------------------------------------

从技术上讲,父1是相同的,但同时用作女性和男性。以上是正确的,但效率低下,重复是不必要的,因为它们只涉及同一个父级。如何删除重复的父级1并将第一行is_female更新为 true

如结果为:

id(pk) | parent_id | parent_name| is_male(boolean) | is_female(boolean)
------------------------------------------------------------------------
1      |     1     |parent1     | true             | true                
------------------------------------------------------------------------
3      |     2     |parent2     | false            | true
------------------------------------------------------------------------

如何在 Yii php 中以编程方式执行此操作?谢谢!

    in update mode loadModel query change means you no need to delete the duplicated , the first record will be get updated 
  Controller file
 ----------------    
          Function loadModel($id)
           {
    $where='id='.$id .' Group by parent_id '
    $model=Model()->find($where);
           }
    in view file 
    ------------
            <?php
            if($model->parent_id==1)  // when the parent_id is 1 the female field will visible , sure not  affect the created 
            {
             echo $form->textField($model, 'is_female'); ?>
            }
        ?>