How can i recreate this sql query with CDbCriteria to use with CActiveDataProvider?
SELECT *
FROM messages AS message
WHERE message.create_time = (
SELECT MAX( create_time )
FROM messages AS message2
WHERE message2.subject = message.subject )
ORDER BY message.create_time DESC
No, there’s no support for subqueries that I’m aware of. It seems like you don’t need to access the content of the subquery from AR so it may work well in your case. (IIRC I once tried a subquery in $criteria->select, but not in $criteria->where)
Edit: Of course it is $criteria->condition, not $criteria->where.