在yii2中LEFT join AND命令

时间:2015-10-13 01:59:16

标签: yii yii2 yii-extensions yii2-advanced-app

我想在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');

1 个答案:

答案 0 :(得分:1)

您是否尝试过以下操作:

$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"');