I want to apply an intersect operator on two SQL queries, but I couldn't find any Yii method for it in CDbCommand. Is there any?
Asked
Active
Viewed 376 times
1 Answers
0
Unfortunately there is no INTERSECT operator in Yiis CDbCommand. But you can use "pure" SQL to make queries.
Examples:
$sql = "first select INTERSECT second select";
$result = Yii::app()->db->createCommand($sql)->queryAll();
You could also use CDbCommands for making single queries, just use buildQuery()
on them. It will looks like:
$firstSql = 'define sql here';
$firstSql->where('your condition');
$secondSql = 'define sql here';
$secondql->where('your condition');
$sql = buildQuery($firstSql) . ' INTERSECT ' . buildQuery($secondSql);
$result = Yii::app()->db->createCommand($sql)->queryAll();
Hope it will help you!

Bfcm
- 2,686
- 2
- 27
- 34
-
For the time being, I have done this only. But this is sort of hack. – Pragya Dalal Sep 16 '15 at 09:02
-
It is normal practice to use pure sql in yii, still not all sql function are implemented. – Bfcm Sep 16 '15 at 09:03