我想在yii2中写一个查询
而且我不知道如何写它
我从文档中尝试了一些东西,但它没有用
这是我的查询
SELECT notification.*,event.title,user.firstname,user.lastname FROM notification
LEFT JOIN event ON event.id = notification.source_id
AND notification.activity_type = "checkin"
Where user.firstname in (select id from user where user_id=1)
LEFT JOIN user ON user.id = notification.source_id
AND notification.activity_type = "friend"
Where user.firstname in (select id from user where user_id=1)
这是我现在写的查询,我需要在查询中添加AND函数
$query ->select(['notification.*,event.title,user.firstname,user.lastname'])
->from('notification')
->leftJoin('event', 'event.id = notification.source_id')
->leftJoin('user', 'user.id = notification.source_id');
最佳答案 您是否尝试过以下方法:
$query ->select(['notification.*,event.title,user.firstname,user.lastname'])
->from('notification')
->leftJoin('event', 'event.id = notification.source_id AND notification.activity_type = "checkin" ')
->leftJoin('user', 'user.id = notification.source_id AND notification.activity_type = "friend"');