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.
Top-N queries provide a method for limiting the number of rows returned from ordered sets of data. They are extremely useful when you want to return the top or bottom "N" number of rows from a set or when you are paging through data.
SQL Server SELECT TOP Clause – TOP-N Analysis You can use the keyword PERCENT to receive a certain percentage of the data, rather than an arbitrary number of rows. The following example returns the top 10 percent earners in the company.
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
LIMIT clause is not available in Oracle.
Seeing your query, you seem to be interested only in a certain number of rows (not ordered based on certain column value) and so you can use ROWNUM clause to limit the number of rows being returned.
select distinct ani_digit, ani_business_line from cta_tq_matrix_exp WHERE rownum <= 5
If you want to order the resultset and then limit the number of rows, you can modify your query as per the details in the link provided by Colin, in the comments above.
select distinct ani_digit, ani_business_line from cta_tq_matrix_exp where rownum<=5;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With