SQL Language (MOSC)

MOSC Banner

Select max(revision) of max(version)

edited Apr 18, 2016 3:41PM in SQL Language (MOSC) 1 commentAnswered

Hello,

I have a table as follows:

filename, filetype, version, revision

file1 fob 00001 00001

file1 fob 00001 00002

file1 fob 00001 00003

file1 fob 00002 00001

file2 fob 00001 00001

file2 fob 00001 00002

file3 fob 00001 00001

file4 fob 00001 00001

file4 fob 00001 00002

file4 fob 00002 00001

I want to select the highest version and revision row for each filename/filetype combination.  The following query DOES NOT return the desired results:

select filename, filetype, max(version) as version, max(revision) as revision

     from cmiaccess.test_table

     group by filename, filetype

     order by filename, filetype;

file1 fob 00002 00003

file2 fob 00001 00002

file3 fob 00001 00001

file4 fob 00002 00002

The next two queries return the desired results. But I am asking: 1(Which one is more efficient.  2(Is there a better way to get the results.

Howdy, Stranger!

Log In

To view full details, sign in to My Oracle Support Community.

Register

Don't have a My Oracle Support Community account? Click here to get started.

Category Leaderboard

Top contributors this month

New to My Oracle Support Community? Visit our Welcome Center

MOSC Help Center