Subject Re: Order By with In Operator Question
Author Adam
--- In firebird-support@yahoogroups.com, "devincayce" <devincayce@...>
wrote:
>
> This is a general sql question, but if I have a query like this:
>
> SELECT * FROM mytable WHERE idnum IN ('203', '102', '355')
>
> How do I get the returned recordset to be in the order of the
records with the IDs listed in the
> "IN" statement like this
> Record 1 idnum = 203
> Record 2 idnum = 102
> Record 3 idnum = 355
>
> When I have tried it so far I get an order other than that.

According to the SQL standard, if you don't explicitly specify the
order of a dataset using an 'Order By' clause, the records will be
returned in an undefined order. In other words, you have told the
database engine that you do not care about ordering, and that it is to
return you the records that match your criteria as quickly as possible.

If you need them returned in a specific order, you will need to use a
field or a set of fields. If the order is provided by the client
application rather than the database engine, then it is probably going
to be faster to order the dataset from the client application than to
pass that information specifically into the database and ask the
database engine to do that same thing.

Adam