Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to union two sql query in yii

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.17k
    Comment on it

    For combine the result of two or more select query we use union in sql query.If you want to use union in yii query you can use the below code

    $queryFirst = (new \yii\db\Query())
        ->select("id, name")
        ->from('tableA')
        ->limit(10);
    
    $querySecond = (new \yii\db\Query())
        ->select('id, name')
        ->from('tableB')
        ->limit(10);
    
    $queryFirst->union($querySecond);
    

    this will be equivalent to

    SELECT id,name FROM tableA
    UNION
    SELECT id,name FROM tableB;
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: