[wp-hackers] Search in 3.0

Casey Bisson casey.bisson at gmail.com
Tue Feb 16 03:13:54 UTC 2010


Perhaps useful MySQL: ORDER BY FIELD(ID, ...list of post ids in the order
you want them...)

SELECT *
FROM wp_posts
WHERE ID IN(5,10,15,20,25,30)
ORDER BY FIELD(ID, 10,30,20,25,5,15)

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_field

Probably not efficient for very large result sets, but...

On Mon, Feb 15, 2010 at 7:40 PM, Andy Skelton <skeltoac at gmail.com> wrote:

> The second example uses a subquery to find the ID's. Subqueries rock.
> You can use them to get the set of ID's from other tables in your
> database. But this example has an important limitation: you can't
> control the order of the final result set by the order of the subquery
> in an IN clause.
>


More information about the wp-hackers mailing list