4 messages in com.mysql.lists.mysqlRe: QUERY ordering clarification
FromSent OnAttachments
Grant Giddens28 Mar 2005 09:42 
Mark Papadakis28 Mar 2005 09:55 
SGr...@unimin.com28 Mar 2005 09:58 
Eamon Daly28 Mar 2005 10:04 
Subject:Re: QUERY ordering clarification
From:Eamon Daly (eda@nextwavemedia.com)
Date:03/28/2005 10:04:51 AM
List:com.mysql.lists.mysql

No, it won't. You'll have to add an ORDER BY clause using FIELD, like so:

SELECT prodname, price FROM prod_table WHERE sku in ($sku1, $sku2, $sku3, $sku4) ORDER BY FIELD(sku, $sku1, $sku2, $sku3, $sku4) ASC

For more information, see page 330 of the MySQL Cookbook, or look for FIELD in the MySQL docs:

http://dev.mysql.com/doc/mysql/en/string-functions.html

Hi,

If I do a query like:

SELECT prodname, price FROM prod_table WHERE sku in ($sku1, $sku2, $sku3, $sku4)

Will my results always be ordered in $sku1, $sku2, $sku3, $sku4 order? I can't really do a ORDER BY prodname or price here.

I just want to make sure that that this type of query will always return the results in $sku1, $sku2, $sku3, $sku4 order.

Thanks, Grant