Converting Mysql Query Into Yii

Hi friends,

      I want to convert this query (select * from tablename where columnname != NULL) into yii. Please help me.


$sql="select * from tablename where columnname != NULL"



Thank you for your replay and i forget to say i want to give this condition using ‘cdbcriteria’. Can you please help me.

This is a solution with CDbCriteria if you’ve got ActiveRecords classes for your tables:

$criteria=new CDbCriteria;

$criteria->select='*';  // is also the default value so you can leave this line out

$criteria->condition='columnname != NULL';


CDbCriteria can be used in AR query methods.

Take a look at Yii Reading Record


For your SQL you should be using "IS NOT NULL" in place of "!= null"

<code>$criteria->condition=‘columnname IS NOT NULL’;</code>


I have one doubt in that ,I want to get the values in one field from the table based user_id how to fetch these values using dataprovider. :(

The answer is in a link already provided.