473,324 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

need same order as the IN list of ids ...

Hi,

I have this Query : SELECT field_name FRM meta WHERE id IN ('13','11','7','8','9','10','12')

I want the rows to be display in the same order as the IN list
of ids.Any ideas?

All the best wished,
Regards and Thanks,
Pong
Apr 2 '08 #1
2 3171
ck9663
2,878 Expert 2GB
Hi,

I have this Query : SELECT field_name FRM meta WHERE id IN ('13','11','7','8','9','10','12')

I want the rows to be display in the same order as the IN list
of ids.Any ideas?

All the best wished,
Regards and Thanks,
Pong
Will this work?
Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2. field_name FRM meta WHERE id IN ('13','11','7','8','9','10','12')
  3. order by case 
  4. when id = 13 then 1
  5. when id = 11 then 2
  6. else id
  7. end
  8.  
if not put in a subquery

Expand|Select|Wrap|Line Numbers
  1. (SELECT top 100 PERCENT
  2. sortid = case 
  3. when id = 13 then 1
  4. when id = 11 then 2
  5. else id
  6. end,
  7. field_name FRM meta WHERE id IN ('13','11','7','8','9','10','12'))
  8. order by sortid
  9.  
try the first one first. it's faster

--CK
Apr 2 '08 #2
You could also consider putting the values inside the "IN" statement in their own table. Then you could solve the problem by doing a simple join, and order by the identity ID in the new table.

If performance is important, this is a solution worth considering.
Apr 4 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Donald Firesmith | last post by:
How do I use XSL to generate and XHTML list of hyperlinks stored in XML? My XML contains links of examples of the form: <examples> <example> <link url="aURL">some text</link> <info>some more...
0
by: Perry Shindle | last post by:
Does anyone no where I can get the latest, up-to-date list of valid values for the CLI PATCH2 keyword? I followed the current link in the on-line DB2 UDB Information Center and it led me to PATCH2...
0
by: Dave Theese | last post by:
Hello all, Our organization is considering a move from C++ to C#. I've been asked to compile a list of the better C# references, but I am new to C# and so don't really know which references...
0
by: Homa | last post by:
Hi to all, My database has two tables: order and orderItem. the order table has (idOrder, name, address, etc) and the orderItem table has (idOrder, idProduct, Quantity) I want to present the...
7
by: Brian Henry | last post by:
I have a list box bound to a data set, of course the datasource,datamember, and valuemember are set, i tell it selecteditem = -1 to make nothing selected, select mode is set to only one item at a...
2
by: federicog | last post by:
I have to create a listing in random order from a few mysql tables. I can't use ORDER BY RAND() for a few reasons: - The random order has to change only every 24hs, ie: today it will show rows...
4
by: supermancc03 | last post by:
I have a List<Point> X(Point pos) which returns a list of coordinates of "neighboring cells" I also have a function getY(int x, int y) that takes in a set of points and returns me a double. I need...
0
by: Academia | last post by:
I've spent the last hour searching the internet for a simple list of the shortcut keys recognized by the Windows Forms RichTextBox and came up empty handed. I did see where someone mentioned...
1
by: Cyprus106 | last post by:
I've got a statement as follows that grabs matching records out two tables: "SELECT * FROM BKRETAIL WHERE BKRETAIL.MATK='THISTHE' UNION SELECT * FROM BKMASTER WHERE BKMASTER.MATK='THISTHE'; My...
3
by: suneelkn | last post by:
Unable to identify the same level for nested lists in all scenarios, when the nested-list inside an ordered list the conversion process executes with out proper list order for nested list items. The...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.