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 7861657
In Process

The Archive Base Latest Questions

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

I have a SQL Server table AccountAction which is denormalised. It is a flattened

  • 0

I have a SQL Server table AccountAction which is denormalised. It is a flattened version of the Account and Action tables, which I’m hoping should be a lot quicker for reporting queries over millions of rows. One Account can have many Actions, so the table looks similar to:

Account     Action
account1    action1
account1    action2
account1    action10
account2    action5

However I’m having some trouble getting the information back for a restricted subset in a simple stored procedure.

select Account, Action
from AccountAction
where ???

What I’m looking for is to get the first X accounts, with all their actions. So this will be a dynamic number of rows. So using the example table above if I passed in 1, I would get 3 rows (i.e. give me all rows for the first account).

(I don’t mind that the account name will be in each row – it is pivoted elsewhere)

Do I need to use a ROWNUM or similar to restrict the rows? I’m sure this must be a simpler issue than I’ve found so far.

EDIT

The answers using TOP won’t work, in the example I’d be wanting 3 rows returned if I said ‘give me one (the first) account’. But how do I know there will be 3? Its dynamic. Also they may not be sequential, what if account1’s action99 was at position 55 million in the results.

  • 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-02T22:48:47+00:00Added an answer on June 2, 2026 at 10:48 pm
    WITH
      SequencedData
    AS
    (
      SELECT
        DENSE_RANK() OVER (ORDER BY Account) AS account_sequence_id,
        *
      FROM
        AccountAction
    )
    SELECT
      *
    FROM
      SequenceData
    WHERE
      account_sequence_id = ???
    

    Or, for multiples…

    WHERE
      account_sequence_id BETWEEN 3 AND 5    -- For the 3rd, 4th and 5th accounts.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an SQL Server 2005 table that has a varchar(250) field which contains
I have a SQL Server 2008 table called users which stores users details. I
I have a sql server 2005 table called ZipCode, which has all the US
I have a SQL Server 2005 table which lists customers and their order lines
I have a SQL Server 2008 table which contains an external user reference currently
I have a SQL SERVER Table which has only one field StartDate the records
I have a SQL Server (2005) table which has nearly 100+ million rows in
I have a sql server 2005 table which has xml store in a text
I have a SQL Server table with 2 columns, Code and CodeDesc. I want
I have a SQL Server table in production that has millions of rows, and

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.