"Webmaster" <[EMAIL PROTECTED]> wrote
in message news:[EMAIL PROTECTED]
> I am trying query for this.
> Find a first occurrence of "Red"
> Then find searching from this record find the previous 4 records that
> contain "White" Then find the Previous 1 that contains "Blue"
> Now do the same thing but searching "next"

select * from (

select * from table1 where Field2='Red' order by Field1 limit 1

union all

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 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 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 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;

Igor Tandetnik 



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

Reply via email to