Answer the question
In order to leave comments, you need to log in
How to build a database query?
For Yii's, the question is actually simple =)
There is a query to the database (the example was taken from the page )
which from one table, selects the values \u200b\u200bof which are not in another table:
SELECT * FROM artist
LEFT JOIN painting
ON artist.a_id = painting.a_id
WHERE painting.a_id IS NULL;
Answer the question
In order to leave comments, you need to log in
$rows = (new \yii\db\Query())
->select(['*'])
->from('artist')
->leftJoin('painting', 'artist.a_id = painting.a_id')
->where(['painting.a_id' => null])
->all();
If there are corresponding models Artist and Painting, then you can do this:
Artist::find()->leftJoin('painting', 'artist.a_id = painting.a_id')->where(['painting.a_id' => null])->all();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question