Subject Re: please help me with this query, TNX!!!
Author fabiano_bonin
Hi, Roberto.
You can use:

order by
1 desc, id desc /* supposing <id> is the name of your key field */

So you will get first the 'big matching' and then, for the results
with the same matching, the last inserted first

--- In ib-support@yahoogroups.com, "Roberto Della Pasqua"
<roberto@d...> wrote:
> Hi Fabiano,
> please forgive me, I like to "use" your kindness again!
>
> Perhaps can you are able to add a thing?
>
> > select
> > ( ( case when x.column1 = :column1 then 1 else 0 end ) +
> > ( case when x.column2 = :column2 then 1 else 0 end ) +
> > ( case when x.column3 = :column3 then 1 else 0 end )
> > ) as column1,
> > x.*
> > from
> > test1 x
> > where
> > ( x.column1 = :column1 ) or
> > ( x.column2 = :column2 ) or
> > ( x.column3 = :column3 )
> > order by
> > 1 desc
>
> I need to do this operation obtaining the last records inserted
first!
> So actually I use order by ID desc to obtain the newer records,
> but I can't use order by with your "case" selection because this
will
> disrupt the order of the big matching...
>
> I need to obtain first the record where x.column1 and x.column2 and
> x.column3 are matched and ordered by id desc THEN
> (as example) x.column1 and x.column2 only ordered by id desc THEN
> then only x.column1 ordered by id desc etc.etc.
>
> I hope to be understood...
>
> TNX again again again anyway!!!!!
>
> Cheers,
>
> Roberto
>
> ----- Original Message -----
> From: "fabiano_bonin" <fabiano@l...>
> To: <ib-support@yahoogroups.com>
> Sent: Monday, June 09, 2003 12:07 AM
> Subject: [ib-support] Re: please help me with this query, TNX!!!
>
>
> > Hi, Roberto.
> >
> > You can do that in a single statement just with the great FB 1.5.
> > In FB 1.0 you will probably need a SP.
> >
> > create table test1 (
> > column1 integer,
> > column2 integer,
> > column3 integer );
> >
> > -> Insert some records
> >
> > select
> > ( ( case when x.column1 = :column1 then 1 else 0 end ) +
> > ( case when x.column2 = :column2 then 1 else 0 end ) +
> > ( case when x.column3 = :column3 then 1 else 0 end )
> > ) as column1,
> > x.*
> > from
> > test1 x
> > where
> > ( x.column1 = :column1 ) or
> > ( x.column2 = :column2 ) or
> > ( x.column3 = :column3 )
> > order by
> > 1 desc
> >
> > -> And you have your big matching ordered first