Search code examples
phpyiiyii2yii2-advanced-appyii2-basic-app

How to convert below sql query into yii2 code


SELECT student_subjects.student_id,student_subjects.subject_id,student_subjects.amount FROM student_subjects where NOT EXISTS(SELECT subject_id from payment_history where student_subjects.subject_id=payment_history.subject_id)


Solution

  • try this

    $sql="SELECT student_subjects.student_id,student_subjects.subject_id,student_subjects.amount FROM student_subjects where NOT EXISTS(SELECT subject_id from payment_history where student_subjects.subject_id=payment_history.subject_id)"
    Yii::app()->db->createCommand($sql)->queryAll();