Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sub Queries

Status
Not open for further replies.

djburnheim

Technical User
Jan 22, 2003
71
AU
Hi I'm very new to informix databases although have a bit of experience with SQL and have managd to put together the below query that returns a maximum for me. I'm now trying to workout out how to find the time that the maximum occured which is stored in the idrecord.IntialStart column.

Query to find max
SELECT max((agerecord.Secondstart -idrecord.Intialstart) + int2interval(agerecord.Length))
FROM agerecord, idrecord
WHERE agerecord.id = idrecord.id
AND ((idrecord.Intialstart Between {ts '2003-06-02 00:00:00'} And {ts '2003-06-03 00:00:00'})


I thought the query to find the time that it occured would be something like:-

SELECT idrecord.IntialStart
FROM agerecord, idrecord
WHERE (SELECT max((agerecord.Secondstart -idrecord.Intialstart) + int2interval(agerecord.Length))
FROM agerecord, idrecord
WHERE agerecord.id = idrecord.id
AND ((idrecord.Intialstart Between {ts '2003-06-02 00:00:00'} And {ts '2003-06-03 00:00:00'})) = (SELECT max((agerecord.Secondstart -idrecord.Intialstart) + int2interval(agerecord.Length))
FROM agerecord, idrecord
WHERE agerecord.id = idrecord.id
AND ((idrecord.Intialstart Between {ts '2003-06-02 00:00:00'} And {ts '2003-06-03 00:00:00'}))


And this does seem to return the right time but it returns it for every row in the table. I added Distinct to the query and the query then took absolutely ages and returned an error "unable to write rows"

Any suggestions?

thanks
Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top