Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

select query

Former Member
0 Likes
551

I have a table with composite primary key as follows

Field 1 Field2

AAA 01

AAA 02

AAA 03

BBB 01

BBB 02

Now I want to select records with max(field2) for a given field1, ie

AAA 03

BBB 02

One way would be to kae it eo an internal table sort by second column descending and take the first record, is there a more elegant way using the MAX clause of the open SQL

4 REPLIES 4
Read only

narin_nandivada3
Active Contributor
0 Likes
527

Hi,

Please check this thread to know how to do with MAX

SELECT Single FIELD1 MAX( FIELD2 ) from......

Hope this solves your issue.

Good luck

Narin

Read only

Former Member
0 Likes
527

hii

you can use query like

Select MAX(VERSION) from ztable into temp1
where OBJECT = temp1
group by version
ordey by version descending.

regards

twinkal

Read only

RaymondGiuseppi
Active Contributor
0 Likes
527

You may use subquery for that

SELECT fielda fieldb INTO (wa_fielda, wa_fieldb)  
  FROM tablename AS t
  WHERE fieldb EQ ( SELECT MAX( fieldb ) 
    FROM tablename WHERE fielda = t~fielda )

Regards

Read only

Former Member
0 Likes
527

hi

select the data from database and put it into Internal table first

then

sort itab field1 field2 by descending

loop at itab.

at new

end at

endloop

Regards

Deva