Work.
But one small issue.
The results are not in order.
Once I changes field1 to "Real" the order by field1 worked great!

"implement logic like this in my application code, rather.."

That's an idea.
To bad I do not know Delphi.

I have a program that is built by Delphi called "PrettyReports"
I do know that I can put Delphi code into the "reports" but I would not have
a clue.

Thanks a bunch.
Now I need to grow my hair back :-)
 

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Igor Tandetnik
Sent: Sunday, November 30, 2008 2:20 PM
To: sqlite-users@sqlite.org
Subject: Re: [sqlite] Select Limit issues

"Webmaster" <[EMAIL PROTECTED]> wrote
in message news:[EMAIL PROTECTED]
> Now I am getting the following error:
> SQL Error: ORDER BY clause should come after UNION ALL not before

Right, you need another level of indirection:

select * from (
    select * from table1 where Field2='Red' order by Field1 limit 1
)
union all
select * from (
    select * from table1 where Field2='White' and
    Field1 < (select Field1 from table1 where Field2='Red' order by 
Field1 limit 1)
    order by Field1 desc limit 4
)
union all
select * from (
    select * from table1 where Field2='Blue' and
    Field1 < (select Field1 from table1 where Field2='Red' order by 
Field1 limit 1)
    order by Field1 desc limit 1
)
union all
select * from (
    select * from table1 where Field2='White' and
    Field1 > (select Field1 from table1 where Field2='Red' order by 
Field1 limit 1)
    order by Field1 limit 4
)
union all
select * from (
    select * from table1 where Field2='Blue' and
    Field1 > (select Field1 from table1 where Field2='Red' order by 
Field1 limit 1)
    order by Field1 limit 1
)
order by Field1;


Personally, I'd implement logic like this in my application code, rather 
than in ever-more-complex SQL statements.

Igor Tandetnik



_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to