yii2中的左连接和命令
我想用yii2编写一个查询 我不知道怎么写 我尝试了一些来自纪录片的东西,但它不起作用 这是我的问题yii2中的左连接和命令,yii,yii2,yii-extensions,yii2-advanced-app,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
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)
这是我现在写的查询,我需要添加和函数,就像它在查询中一样
$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"');
谢谢你的重播。。它仍然有一些问题,但我有了这个想法,并且能够解决。你知道如何在yii2中编写
where user\u id in(子查询)
。。。我想在相同的$query
中包含where条件。。。更新问题