0

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?

Anders
  • 8,307
  • 9
  • 56
  • 88
Pragya Dalal
  • 68
  • 2
  • 9

1 Answers1

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