如何将此sql语句转换为yii格式以构建模型?
SELECT DISTINCT agency_id, university_id
FROM `tbl_universityagency` where agency_id=1
像这样我缺少什么? ,
$criteria = new CDbCriteria();
$criteria->distinct=true;
$criteria->condition = "agency_id=".$result->agency_id ;
$modal=Universityagency::model()->find($criteria);
最佳答案
$criteria = new CDbCriteria();
$criteria->distinct=true;
$criteria->condition = "agency_id=".$result->agency_id ;
$criteria->select = 'id, agency_id, university_id';
$modal=Universityagency::model()->find($criteria);
应该产生查询:
SELECT DISTINCT id,agency_id, university_id FROM `tbl_universityagency` where agency_id=1 LIMIT 1
关于select - 如何在Yii中从具有条件的表中选择两列的DISTINCT?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17540591/