Answer the question
In order to leave comments, you need to log in
How to write LEFT JOIN ON ..OR in yii2?
There is a working request:
SELECT
COUNT(`user`.`id`) AS `count`,
`user`.`id` AS `id`,
`user`.`username` AS `username`,
`user`.`email` AS `email`,
`user`.`FIO` AS `FIO`,
`user`.`status` AS `status`,
`user`.`phone` AS `phone`
FROM (`user`
LEFT JOIN `event` `e`
ON (((`user`.`id` = `e`.`id_operator`)
OR (`user`.`id` = `e`.`id_operator2`)
OR (`user`.`id` = `e`.`id_journalist`)
OR (`user`.`id` = `e`.`id_driver`))))
WHERE (`e`.`status` = 1)
GROUP BY `user`.`username`,
`user`.`email`,
`user`.`FIO`,
`user`.`status`,
`user`.`phone`
...
->joinWith('operator',true,'LEFT JOIN')
->joinWith('journalist jour',true,'LEFT JOIN')
...
Answer the question
In order to leave comments, you need to log in
$newquery = User::find()
->select(['username',new Expression('count(id) as id')])
-> leftJoin('event', 'event.id_operator=user.id OR event.id_driver=user.id OR event.id_operator2=user.id OR event.id_journalist=user.id')
->where(['event.status'=>1])
->groupBy(['username'])
->all();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question