Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Wikipedia: Wikitech

SQL

 

 

Wikipedia wikitech RSS feed   Index | Next | Previous | View Threaded


qli at ica

Nov 26, 2009, 2:28 AM

Post #1 of 3 (551 views)
Permalink
SQL

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

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


tstarling at wikimedia

Nov 26, 2009, 4:23 AM

Post #2 of 3 (497 views)
Permalink
Re: SQL [In reply to]

李琴 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
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


roan.kattouw at gmail

Nov 26, 2009, 4:32 AM

Post #3 of 3 (498 views)
Permalink
Re: SQL [In reply to]

2009/11/26 Tim Starling <tstarling [at] wikimedia>:
> 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__ );
>
Note that the GROUP BY condition in the first query is unnecessary,
and that the whole thing could be rewritten to SELECT * FROM
recentchanges WHERE rc_namespace=0 AND rc_title='Wiki' ORDER BY rc_id
DESC LIMIT 1;

Roan Kattouw (Catrope)

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

Wikipedia wikitech RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.