UNIONクエリを入れたいSQLクエリを1つ作成したかったのですが、そのUNIONクエリは特定の条件に基づいていますが、Yiiクエリビルダーを使用して作成することは可能ですか。
以下は、DAOだけで作成したサンプルコードですが、クエリビルダースタイルで作成したいと思います。
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();