oracle - select only one row that has the highest count in sql -


i need select 1 row has highest count. how do that?

this current code:

 select firstname, lastname, count(*) total  trans   join work   on trans.workid = work.workid  join artist  on work.artistid = artist.artistid  datesold not null  group firstname, lastname; 

example current:

firstname |  lastname |  total ------------------------------ tom       |   cruise  |   3 angelina  |   jolie   |   9 britney   |   spears  |   5 ellie     |  goulding |   4 

i need select this:

firstname  |  lastname  |  total -------------------------------- angelina   |  jolie     |   9 

in oracle 12, can do:

 select firstname, lastname, count(*) total  trans join       work        on trans.workid = work.workid join       artist       on work.artistid = artist.artistid  datesold not null  group firstname, lastname  order count(*) desc  fetch first 1 row only; 

in older versions, can subquery:

select twa.* (select firstname, lastname, count(*) total       trans join            work             on trans.workid = work.workid join            artist            on work.artistid = artist.artistid       datesold not null       group firstname, lastname       order count(*) desc      ) twa rownum = 1; 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -