I need to limit the results from a query, but I can’t implement any example I’ve seen using count and rownum. Given this table
rec error
___ _____
1 123
2 123
3 456
4 456
5 456
6 456
7 456
8 456
9 456
10 789
11 789
12 789
13 789
This table has many more rows with many different error codes. I’m using this to get the records i need:
select rec, error from table where error in (123,456,789)
But say I want to only return no more than 2 records per error. I’m not sure how to do this. If I was only looking for a single error, I could simply use count or rownum. Not sure how to do it when using the IN condition.
Do you care which two rows you get for any particular error code? Something like this will get you the two rows for each error code with the smallest
recvalue. If you change theORDER BYin theROW_NUMBERanalytic function, you can change which two rows are returned.