Difference between #1 and #2 of
Using sub query for doubletts

Revision #2 has been created by mb on Apr 21, 2013, 12:33:26 PM with the memo:

more details..
« previous (#1)

Changes

Title unchanged

Using sub query for doubletts

Category unchanged

Tips

Yii version unchanged

Tags unchanged

active record, cdbcriteria, subquery, doubletts

Content changed

at first find doubletts by db fields:
 
find doubletts by db fields.
 
in this example i will check doublets for 3 tabelfields (col1,col2,col3).
 
so i will get a subquery with the condition, select and grouping of the tablefields. the having with COUNT(<colname>) > 1 means: find all records more then one result.


```php
[...]
get the subquery:
the subquery is a part of the query i need.

```php
[...]
the "real" criteria with the subquery. you can add some criteria you need..
 
important: the number of col and the result of the subquery must be the same size!
add the subquery condition and order by tablefields:


```php
$mainCriteria=new CDbCriteria();
$mainCriteria->condition=' (col1,col2,col3) in ('.$subQuery.') ';
[...]
3 0
10 followers
Viewed: 25 046 times
Version: 1.1
Category: Tips
Written by: mb
Last updated by: mb
Created on: Aug 7, 2012
Last updated: 11 years ago
Update Article

Revisions

View all history