Codxplore.com

Latest news: New android application Islamic Video has been released. its a free islamic video application for android smartphone. Download now!


innerJoinWith()

$model = User::find()
    ->innerJoinWith('comments', false)
    ->all();
// equivalent to the above
$model = User::find()
    ->joinWith('comments', false, 'INNER JOIN')
    ->all();

SYNTAX:

$query = new Query;
$query    ->select(['SELECT COLUMNS'])  
        ->from('TABLE_NAME_1')
        ->join(    'JOIN_TYPE',
                'TABLE_NAME_2',
                'TABLE_NAME_2.COLUMN =TABLE_NAME_1.COLUMN'
            );
$command = $query->createCommand();
$data = $command->queryAll();               

Sample 1:

$query = new Query;
$query    ->select([
        'tbl_user.username AS name',
        'tbl_category.categoryname as  Category',
        'tbl_document.documentname']
        ) 
    ->from('tbl_user')
    ->join('LEFT OUTER JOIN', 'tbl_category',
                'tbl_category.createdby =tbl_user.userid')        
    ->join('LEFT OUTER JOIN', 'tbl_document',
                'tbl_category.cid =tbl_document.did')
    ->LIMIT(5)    ;
       
$command = $query->createCommand();
$data = $command->queryAll();   

Tags : PHP, Yii2,

Views : 2002

Subscribe Us


Follow Us