i wanted to prepare one SQL query in which i wanted to put UNION query but that UNION query is based on certain condition, is it possible to make using Yii query builder.
below is sample code which i have made with simply DAO but i want to make it in query builder style
if(isset($first) && $first!="")
$con .= "SELECT id,first, from user where first LIKE '%".$first."%'";
if(isset($last) && $last!="")
$con .= " AND last LIKE '%".$last."%'";
if((!empty($first) || !empty($last)) && (!empty($flag)) )
$con .= " UNION SELECT id,first, from user where flag = 1"
$command = $connection->createCommand($con)->queryall();
Yes, it sure is. Assuming this were your test code:
Some sample other lines from the Query Builder page
But the main one you’ll want to look at is
union()