李琴 wrote:
>  hi,
> 
> I want to find something in wikidb. But I don't exectly know  how to use the 
> select  statement write in WIKI.
> 
> For ecample . 
> DatabaseBase::select ($ table, 
> $ vars, 
> $ conds = '', 
> $ fname = 'Database::select', 
> $ options = array(), 
> $ join_conds = array() 
> )
> 
> How can  I use this to rewrite ' select * from recentchangs  where rc_id 
> in(selcet max(rc_id) from recentchangs group by rc_title) and 
> rc_title='Wiki' '.
> 
> 
> Thanks very much!
> 
>          vanessa lee

Don't use subselects, they're not supported by MySQL 4.0 which is what
we target.

$dbr = wfGetDB( DB_SLAVE );

$max = $dbr->selectField(
        'recentchanges',
        'max(rc_id)',
        false,
        __METHOD__,
        array( 'GROUP BY' => 'rc_title' );

$res = $dbr->select(
        'recentchanges',
        '*',
        array(
                'rc_id' => $max,
                'rc_namespace' => 0,
                'rc_title' => 'Wiki',
        ),
        __METHOD__ );

foreach ( $res as $row ) {
        // $row is the result row
}

The rc_namespace condition is necessary.

-- Tim Starling


_______________________________________________
Wikitech-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Reply via email to