Subject Re: SQL ORDER BY problem
Author csswa
What's wrong with this in a SELECT stored proc, or did I not follow
your logic?

if
(
exists
(
select 1 from TableA
where (c1 = x and c2 = y)
)
)
then
select * from TableA
where (c1 = x and c2 = y);
else
select * from TableA
where c1 = x;

It walks the data until it finds a match (it needs only one), at
which point the EXISTS condition becomes true so it exits to do the
first-case select. If it walks the entire db without finding a first-
case match then it does the second-case select. EXISTS is my
favourite keyword :-)

Regards,
Andrew Ferguson
-- A cop on the edge.



--- In ib-support@y..., "mircostange" <mirco@i...> wrote:
> Hi Everyone,
>
> I am having a problem to find an appropriate SQL select statement
for
> the following scenario.
> I have a table (say A) with columns (say c1, c2, etc). What I need
> now is a select statement that returns
>
> all rows with c1=x and c2=y
> OR
> if no such row exists any c1=x
>
> This doesnt seem to be possible, so I am trying to figure out
whether
> I can select all rows with c1=x, but
> * ordered so that rows with c2=y appear on the top *
>
> It seems that
> SELECT * from A where c1=x ordered by c2=y
> does not work.
>
> Any alternatives?
>
> Mirco