query incorrect

hi guys, following query in plain sql will give me result as desired…




SELECT nachname FROM person LEFT JOIN e_kontakt ON person.id=e_kontakt.id_person where person.id=e_kontakt.id_person order by nachname;






last name:

Smith

Wilson



I want to get this values in a DropDownbox,but I get result(no error): No matching found. What do I wrong?





  public static function nachname_for_ekontakt() {


        $nachname = Person::find()

                        ->leftJoin('e_kontakt', 'person.id=e_kontakt.id_person')

                        ->where(['person.id' => 'e_kontakt.id_person'])->orderBy(['nachname' => SORT_ASC])->asArray()->all();

        return yii\helpers\ArrayHelper::map($nachname, 'id', 'nachname');

    }



Why don’t you use an INNER JOIN instead LEFT JOIN? Because in where condition you apply the same condition expressed in ‘on’.




SELECT nachname FROM person INNER JOIN e_kontakt ON person.id=e_kontakt.id_person order by nachname;






  public static function nachname_for_ekontakt() {


        $nachname = Person::find()

                        ->innerJoin('e_kontakt', 'person.id=e_kontakt.id_person')

                         ->orderBy(['nachname' => SORT_ASC])->asArray()->all();

        return yii\helpers\ArrayHelper::map($nachname, 'id', 'nachname');

    }



Bingo. U were right. I didn’t bring in mind different JOINs in this case. Nevertheless, I get surprised that ur solution works, 'cause phpmyadmin works with both JOINS,yii

only with INNER JOIN. I know difference betwenn INNER JOIN and LEFT JOIN. so my final question is following:

Why will yii distinguish INNER and LEFT JOIN, but phpmyadmin will not? Both is PHP…

Why would not phpmyadmin distinguish INNER and LEFT JOIN?

It will distinguish, but phpmyadmin will accept both JOINs in my case, but yii won’t. Why?

I think that the error was in the code, because I don’t think that Yii distinguishes this automatically.

All right. Thx a lot for ur help