SQL ORDER BY

  • Thread starter Thread starter Kalle
  • Start date Start date
K

Kalle

HI

I use this question and it works fine but I want to sort it in the same
order as the "IN list"

SELECT ID, firstname, lastname FRON person WHERE ID IN (6,2,8)

Now I want it to be sorted in the same order as "IN (6,2,8)" I mhave
tried ORDER BY FIELD(ID, 6,2,8) but then I get an error

IS thier someone who knows somthing about this?

Thanks in advance
 
You'll have to use something like decode() to do this.

.... order by decode(ID,6,1,2,2,8,3)

or whatever is the equivalent in your particular database.

Tim
 
Hi


Thanks for your answer but it does't work.

I use an excel worksheet as datebase. Maybe it does't support decode?

Kalle
 
sSQL = " select col1, col2 from src_rng_name " & _
" order by switch(col1=6, 1, col1=6, 2, col1=6, 3) "

Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top