0

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,89,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,6 3,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.

Tejas Kale
  • 415
  • 8
  • 18
Vikas Kale
  • 53
  • 1
  • 2
  • 7
  • Maybe you should do a `select STRINGTEXT,TOKENID ....` , then you will have the `TOKENID` and `STRINGTEXT` mapping in your result. – Tejas Kale Mar 19 '14 at 05:08

2 Answers2

0

Try using 'ORDER BY FIELD`

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,89,90,208,210,249,309,310,311) 
ORDER BY FIELD (TOKENID,312,47,48,49,50,51,52,53,54,55,56,57,58,60,61,62,6 3,87,88,89,90,208,210,249,309,310,311)
CyberBoy
  • 745
  • 1
  • 7
  • 31
  • 1
    what is the problem? can you add the new code and error/output in the question. It should give the correct result. – CyberBoy Mar 19 '14 at 05:22
  • It seems there is a typo in feed to `FIELD` function. *`...61,62,6 3,87,...`* should be *`...61,62,63,87,...`*. Remove the space in it. – Ravinder Reddy Mar 19 '14 at 05:33
0
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,89,90,208,210,249,309,310,311);
ORDER BY FIELD(TOKENID,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);

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