I know, I know... this is not really an MySQL question but an ordinary SQL
question.. but I need help with it..

Lets say that I have a table called test that has 3 columns
test1,test2,test3 (what type they are are not interesting) columns test1 and
test2 makes the primary key

what I would like is something like the following

select *,FIND_IN_SET(test2,'9,5,7') test2order
from test
where test1=1 and PERIOD_ID=1
order by test2order DESC

(values in column test2 should be ordered by 9,5,7,all the rest)

but I would ONLY want the first row of the keys (test1,test2) ie if it finds
a 9 it would return that row but not any other row
if it doesnot find a row with value 9 it should return the one with value 5,
etc...

so I thought that by doing a group by would sort this (grouping by columns
test1,test2)

select *,FIND_IN_SET(test2,'9,5,7') as test2order
from test
where test1=1 and PERIOD_ID=1
group by test1,test2
order by test2order DESC

I do get 1 row, but not the row I want.. since unfourtunally group by is
"executed" before order by, and I will not get the list in the order I want
it

IE I want the query sorted BEFORE the group by

I have also tried doing it like this

select *,FIND_IN_SET(test2,'9,5,7') test2order
from test
where test1=1 and PERIOD_ID=1 and test2order=max(test2order)
order by test2order DESC

but that will not work either

is there any way to do this in sql?  in mysql?





---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to