How to select top five or 'N' rows in Oracle 11g

Karthikeyan Sukkoor picture Karthikeyan Sukkoor · Dec 18, 2013 · Viewed 58k times · Source
select distinct ani_digit, ani_business_line from cta_tq_matrix_exp limit 5

I want to select top five rows from my resultset. if I used above query, getting syntax error. Thanks advance

Answer

D Stanley picture D Stanley · Dec 18, 2013

You'll need to use DISTINCT before you select the "top 5":

SELECT * FROM 
(SELECT DISTINCT ani_digit, ani_business_line FROM cta_tq_matrix_exp) A
WHERE rownum <= 5