Subject RE: [firebird-support] Order By with In Operator Question
Author Alan McDonald
> > devincayce wrote:
> >> This is a general sql question, but if I have a query like this:
> >>
> >> SELECT * FROM mytable WHERE idnum IN ('203', '102', '355')
> >>
> >> How do I get the returned recordset to be in the order of the records
> >> with the IDs listed in the
> >> "IN" statement like this
> >> Record 1 idnum = 203
> >> Record 2 idnum = 102
> >> Record 3 idnum = 355
> >>
> >> When I have tried it so far I get an order other than that.
> >
> > SELECT CASE idnum
> > WHEN '203' then 1
> > WHEN '102' then 2
> > WHEN '355' then 3
> > END AS myorder, m.*
> > FROM mytable m
> > WHERE idnum IN ('203', '102', '355')
> > ORDER BY 1
> >

this works

> > SELECT CASE idnum
> > WHEN '203' then 1
> > WHEN '102' then 2
> > WHEN '355' then 3
> > END AS myorder, m.*
> > FROM mytable m
> > WHERE idnum IN ('203', '102', '355')
> > ORDER BY CASE idnum
> > WHEN '203' then 1
> > WHEN '102' then 2
> > WHEN '355' then 3
> > END

Alan