CDbCriteria Sample in YII

Sample

<?php
$criteria = new CDbCriteria;
$criteria->mergeWith(array(
    'join'=>'LEFT JOIN user_group ug ON ug.user_id = t.id',
    'condition'=>'ug.group_id = 0 OR ug.group_id IS NULL',
));
User::model()->findAll($criteria);
?>

Sample

<?php
class Mymodel extends CActiveRecord {
    public function relations() {
        return array(
            'mySecondTable' => array(self::HAS_MANY, 
                                  'MySecondTable', 'second_table_id'),
        );
    }
}
public function searchWithRelated() {
        $criteria = new CDbCriteria;
       //without this you wont be able to search the second table's data
        $criteria->together = true; 
        $criteria->with = array('mySecondTable');
        $criteria->compare('id', $this->id, true);
        $criteria->compare('mySecondTable.column', 
                            $this->mySecondTable_column, true);
       return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
            'sort'=>array(
                'defaultOrder'=>'t.id DESC',
            ),
            'pagination' => array(
                'pageSize' => 100,
            ),
        ));
    }
?>

Sample

$criteria->compare('year(`EventStartdate`)','>=:'.$currentYear); 
$criteria->compare('year(`EventStartdate`)','>='.$currentYear); 
?>