Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7864581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:49:44+00:00 2026-06-02T23:49:44+00:00

I need to limit the results from a query, but I can’t implement any

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:49:45+00:00Added an answer on June 2, 2026 at 11:49 pm

    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 rec value. If you change the ORDER BY in the ROW_NUMBER analytic function, you can change which two rows are returned.

    SELECT rec,
           error
      FROM (SELECT rec,
                   error,
                   row_number() over (partition by error
                                          order by rec asc) rnk
              FROM your_table_name)
     WHERE error in (123,456,789)
       AND rnk <= 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can get the results that I need, but I need a fast query.
How can I limit the number of results when using group() in MongoDB? Basically
I need to limit the number of characters that can be appended to an
I need to limit the input from a user to only positive values, and
I need to query my database and partially order and randomize the results. For
Here is an easy one, but can't figure out why is not working. Need
I am making a multi-table fulltext query.But I met some question. I need make
I managed to create a query that fit my need. But now I am
I need to limit the amount of time and cpu taken by external command
I have a PHP page I need to limit execution access of to only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.