You don't have the group by clause (at least you are not showing it here) in your RPG program. Also group by should come before order by.
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Gqcy
Sent: Thursday, May 19, 2011 3:27 PM
To: rpg400-l@xxxxxxxxxxxx
Subject: SQL - group by not working for me.
I have a query I can get to work in STRSQL, but not getting it
to compile in SQLRPGLE...
the premise of the query is to return the latest instance of a user
running a menu option. I have a menu file, and a menu log file.
for every menu file record I retrieve, I want to find the "Latest" time
the user ran that option...
I can't get my SQLRPGLE to accept the GROUP BY, or something else is
wrong!!!
here is my SQL that works in STRSQL:
select mnuprf, mnugrp, mnuopt, mnucmd, mnuonm, max(mts) from
(select mnucmd, mnuprf, mnugrp,
mnuopt, mnuonm, mltimstmp as mts
from pdatalib/menupf
join pdatalib/menulog on mnuprf = mlnuprf and
mnugrp = mlnugrp and
mnuopt = mlnuopt
where mnucmd like ('%ORD500%')
order by mnuprf, mnugrp, mnuopt) as list1
group by mnuprf, mnugrp, mnuopt, mnucmd, mnuonm
here is my RPG that won't compile...
each of the fields in my outer select have a "Column XXXXXX or
expression in SELECT list not valid" (SQL0122)
exec sql declare LOAD cursor for
select mnuprf, mnugrp, mnuopt, mnucmd, mnuonm, max(mts) from
(select mnucmd, mnuprf, mnugrp, mnuopt, mnuonm, mltimstmp as mts
from pdatalib/menupf
join pdatalib/menulog on mnuprf = mlnuprf and
mnugrp = mlnugrp and
mnuopt = mlnuopt
where mnucmd like (:fmtScanVals)
order by mnuprf, mnugrp, mnuopt)
ROWS for fetch only;
Thanks...
--
This is the RPG programming on the IBM i / System i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at
http://archive.midrange.com/rpg400-l.
________________________________
Notice from Bob Evans Farms, Inc: This e-mail message, including any attachments, may contain confidential information that is intended only for the person or entity to which it is addressed. Any unauthorized review, use, disclosure or distribution is strictly prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message and any attachments.
As an Amazon Associate we earn from qualifying purchases.