How do I get MySQL to NOT sort my resultset?

How do I get MySQL to NOT sort my resultset?

am 12.03.2006 16:58:24 von Laphan

Hi All

The following query works, but MySQL sorts the results set:

SELECT STRINGTEXT FROM WEBSTRINGS WHERE GUI=0 AND LANGID='GB' AND TOKENID IN
(312,47,48,49,50,51,52,53,54,55,56,57,58,60,61,62,63,87,88,8 9,90,208,210,249,309,310,311);

This means that when I grab this in my recordset the data for TOKENID 312 is
at the end rather than being the first one, eg

I expected my resultset to come back in the following order of requests:

312,47,48,49,50,51,52,53,54,55,56,57,58,60,61,62,63,87,88,89 ,90,208,210,249,309,310,311

but it comes back as:

47,48,49,50,51,52,53,54,55,56,57,58,60,61,62,63,87,88,89,90, 208,210,249,309,310,311,312

Is there anyway to get MySQL to not do this for this query? I really need
them to come back as is.

Thanks

Laphan

Re: How do I get MySQL to NOT sort my resultset?

am 13.03.2006 03:02:32 von avidfan

Laphan wrote:
> Hi All
>
> The following query works, but MySQL sorts the results set:
>
> SELECT STRINGTEXT FROM WEBSTRINGS WHERE GUI=0 AND LANGID='GB' AND TOKENID IN
> (312,47,48,49,50,51,52,53,54,55,56,57,58,60,61,62,63,87,88,8 9,90,208,210,249,309,310,311);
>
> This means that when I grab this in my recordset the data for TOKENID 312 is
> at the end rather than being the first one, eg
>
> I expected my resultset to come back in the following order of requests:
>
> 312,47,48,49,50,51,52,53,54,55,56,57,58,60,61,62,63,87,88,89 ,90,208,210,249,309,310,311
>
> but it comes back as:
>
> 47,48,49,50,51,52,53,54,55,56,57,58,60,61,62,63,87,88,89,90, 208,210,249,309,310,311,312
>
> Is there anyway to get MySQL to not do this for this query? I really need
> them to come back as is.
>
> Thanks
>
> Laphan
>
>
>


One thing about SQL and databases - you do not know what order the data
is going to be returned - unless you specifically order it (ORDER BY)
but then you only get ASC or DESC.

So, your only option would be to read this into an array and select the
last member of the array first, then process the rest - and depending on
your programming language and your skill as a programmer, this could be
simple or quite challenging.

select...
order by tokenid asc;