1

I have the following Order By which I expect to output in ROID order. Instead the output appears in OIDR order. Why would the R be at the end instead of the beginning?

select narritive_section as ns, decode(narritive_section,'R','Origin','O','Initial Observation','I','Investigation','D','Disposition') as narritive_section 
    ,person_id, offense_id, entry_date, narritive_text, c_narritive_text  
from t_narritive 
where not narritive_text is null and offense_id =  11514
order by offense_id, decode(
    narritive_section, 'R',1, 'O',2, 'I',3, 'D',4);
1
  • 1
    You're ordering by offense_id first, so that's the main driver of the order. Try order by decode(narritive_section, 'R',1, 'O',2, 'I',3, 'D',4), offense_id instead.
    – Ed Gibbs
    Aug 8, 2013 at 21:22

1 Answer 1

1

You have offense_id with higher sort priority then ROID sort. Switching the two parameters in order by should solve your issue.

select narritive_section as ns, decode(narritive_section,'R','Origin','O','Initial Observation','I','Investigation','D','Disposition') as narritive_section, person_id, offense_id, entry_date, narritive_text, c_narritive_text
from t_narritive
where not narritive_text is null and offense_id = 11514
order by decode(narritive_section, 'R',1, 'O',2, 'I',3, 'D',4), offense_id;
1
  • I got rid of the the Decode and replaced it with CASE and added an nrank column to be used for sorting. Worked like a charm.
    – oaksong
    Sep 4, 2013 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.