Sunday, 8 September 2013

Correlated Sql Query is not giving the desired output

Correlated Sql Query is not giving the desired output

I am using SqlLite. My table consists of jobno's and the time (ondate) on
which it was created. I want to select the most recent jobno from each
groups.
The ondate contains values in this format 09/08/2013 04:04:30 So I have
done ordering of ondate little differently.
select r1.jobno, r1.ondate from reports r1 where
(
select r2.jobno from reports r2 where r1.jobno=r2.jobno ORDER BY
substr(r2.ondate,7,4)||
substr(r2.ondate,1,2)||
substr(r2.ondate,4,2)||
substr(r2.ondate,11) desc
) group by jobno <=1
The ordering by ondate is correct. It gets ordered properly.
The correlated Query is wrong it is not giving me the correct output. Can
anyone please help me correcting this query.

No comments:

Post a Comment