How to convert this sql statement to yii format build a model?
SELECT DISTINCT agency_id, university_id
FROM `tbl_universityagency` where agency_id=1
like this what I am missing? ,
$criteria = new CDbCriteria();
$criteria->distinct=true;
$criteria->condition = "agency_id=".$result->agency_id ;
$modal=Universityagency::model()->find($criteria);
To select distinct values in two columns, you can use least() and greatest() function from MySQL.
Select with distinct on all columns of the first query. Select with distinct on multiple columns and order by clause. Count() function and select with distinct on multiple columns.
Multiple fields may also be added with DISTINCT clause. DISTINCT will eliminate those rows where all the selected fields are identical.
To get unique or distinct values of a column in MySQL Table, use the following SQL Query. SELECT DISTINCT(column_name) FROM your_table_name; You can select distinct values for one or more columns. The column names has to be separated with comma.
$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);
Should produce query:
SELECT DISTINCT id,agency_id, university_id FROM `tbl_universityagency` where agency_id=1 LIMIT 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With