CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation:

I’m trying to execute this query and resulted in an exception…Any other ways to make it work…


   <?php

			$criteria=new CDbCriteria;

			$criteria->condition='select min(purchase_order_id) from purchase_order where purchase_order_id >'.$model->purchase_order_id;

			$nextfield = \POrder::model()->model()->findAll($criteria);

			   ?>

The exception is,

CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘select min(purchase_order_id) from purchase_order where purchase_order_id >65’ at line 1. The SQL statement executed was: SELECT * FROM purchase_order t WHERE select min(purchase_order_id) from purchase_order where purchase_order_id >65

What exactly U want to do, asking because U are placing full query in ‘condition’. U should use it something like:

&#036;criteria-&gt;condition='purchase_order_id &gt;'.&#036;model-&gt;purchase_order_id;

This is probably not what U want, but this is how condition should be set.