Question: I need to show the most frequent value between two groups on a selection, and it has to go along a message, so bear with me. I'm using Oracle XE and this is what I've got so far:

```
SELECT (
    CASE type
        WHEN 0 THEN 'heroes'
        WHEN 1 THEN 'villains'
        ELSE 'neither'
    END
) AS MostFrequent
FROM (
    SELECT type
    FROM mutants
    GROUP BY type
    ORDER BY count(*) DESC
) WHERE rownum <= 1

```

So far if there are more Mutants with type 0 than type 1 it shows Heroes and then when there are more of type 1 than type 0, it shows villains, but when they're tied, it shows no data, and that doesn't work for me :( I need it to say 'neither', so any help will be widely appreciated.

Answer: 
```
WITH
RECOUNTS AS
(    
  SELECT
    NVL(COUNT(CASE TYPE WHEN 0 THEN TYPE END), 0) AS HEROES,
    NVL(COUNT(CASE TYPE WHEN 1 THEN TYPE END), 0) AS VILLAINS
  FROM MUTANTS
)
SELECT
  CASE WHEN HEROES > VILLAINS THEN 'heroes'
       WHEN HEROES < VILLAINS THEN 'villains'
       ELSE 'neither'
  END AS MOSTFREQUENT
FROM RECOUNTS

```
Have a look at this [SQL Fiddle](http://sqlfiddle.com/#!4/f14e9/15)

```
select 
   case when heroes > villains then 'heroes'
        when heroes < villains then 'villains'
        else 'neither'
   end as MostFrequent  
from ( select 
        (select count(*) from mutants where type = 0) as heroes,
        (select count(*) from mutants where type = 1) as villains
      from dual)
;

```

The bottom line is that you cannot decide for "neither" without having the result for both. To achieve this you involve a subquery doing the count first. The counting can be done in different ways the above is probably a bit less efficient then the suggestion from GuiGi which also works, see this [SQL Fiddle](http://sqlfiddle.com/#!4/f14e9/16)