coldfusion - SQL... Get Value from Field based on Max value of Another Field -
having complete sql mental lapse today , can't figure out. coldfusion , ms access
i'm looking query of query in coldfusion.
original query:
<cfquery name="myquery" datasource="xxx"> select name, id, tblloc.directions, tblloc.locationorder mytable ..... order tblloc.locationorder </cfquery>
i want create query query retrieve directions locationorder max.
thus, if myquery returned:
name id directions locationorder aa 10 aaaaaa 1 bb 11 bbbbbb 2 qoq return: directions bbbbbb
but every iteration of seemingly simple sql i've tried fails. must half-asleep or something.
<cfquery name="latestdirections" dbtype="query"> select directions myquery locationorder=(select max(locationorder) myquery) </cfquery> <cfquery name="latestdirections" dbtype="query"> select directions, max(locationorder) maxlocationorder get_sel_locations </cfquery>
nope... neither it.
...the second, "column get_sel_locations.directions invalid in select list clause because not contained in aggregate function , there no group clause"
the error pretty clear. missing group clause. when using aggregates max() have group results non-aggregated columns. in case: directions
select directions, max(locationorder) maxlocationorder get_sel_locations group directions
update if want maximum everything, yisroel's query want.
update mentioned in comments, qoq not database queries. support functions/syntax listed in documentation http://livedocs.adobe.com/coldfusion/8/using_recordsets_3.html
Comments
Post a Comment