leftjoin در Yii2

برای استفاده از leftjoin در کوئری ها به روش زیر عمل می کنیم

$query = new Query;
$query	->select(['tbl_user.username AS name', 'tbl_category.type as Category'])  
		->from('tbl_user')
		->leftJoin('tbl_category', 'tbl_category.createdby = tbl_user.userid')
		->limit(2); 		
$command = $query->createCommand();
$data = $command->queryAll();

خروجی به صورت زیر :

SELECT `tbl_user`.`username` AS `name`, `tbl_category`.`type` AS `Category`
	FROM `tbl_user` LEFT JOIN `tbl_category` 
	ON tbl_category.createdby = tbl_user.useridd 
	LIMIT 2		

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *