Subject | Re: [firebird-support] Select last - How to select latest data |
---|---|
Author | Andreas Hesse |
Post date | 2005-12-08T14:18:06Z |
menjit_singh wrote:
First step) "select first 30 id from data order by data desc;"
and collect the result in a string like "(id1,id2,...)"
Second step) "select * from data where id in " result from step 1 "
order by data asc;"
I tried both together, but that does not work:
"select * from data where id in (select first 30 id from data order by
data desc) order by data asc;"
The result set was allways the hole table.
Perhaps someone can explain, why this does not work?
Andreas
> Hello all,If you can build in a 2 step process you can use "IN"
>
> What is the syntax to select the latest 30 days data and sort it from
> oldest date to most recent date? (please refer message id 26907,
> question about the same, but i need to change it a bit). I have
> tried :
>
> 'SELECT First 30 CLS, VOL, OPN, HIGH, LOW, DATA,symbol FROM DATA
> WHERE STOCK='''+imya+''' order by DATA ACS'
>
> With the statement above i got the first 30 days data sorted from the
> oldest date to the most recent date.
>
> 'SELECT First 30 CLS, VOL, OPN, HIGH, LOW, DATA,symbol FROM DATA
> WHERE STOCK='''+imya+''' order by DATA DESC'
>
> with the statement above i got the last 30 days data BUT sorted from
> the latest date to the oldest date.
>
> Now i want the latest 30 days data SORTED from the oldest date to the
> most recent date.
>
> PS: i have a table called DATA and a field in that table named DATA
> to store date information.'imya' refers to the stock name. 'CLS, VOL,
> OPN, HIGH, LOW, DATA,symbol' are the fields in the table.
>
First step) "select first 30 id from data order by data desc;"
and collect the result in a string like "(id1,id2,...)"
Second step) "select * from data where id in " result from step 1 "
order by data asc;"
I tried both together, but that does not work:
"select * from data where id in (select first 30 id from data order by
data desc) order by data asc;"
The result set was allways the hole table.
Perhaps someone can explain, why this does not work?
Andreas