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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:45:38+00:00 2026-05-22T22:45:38+00:00

Imagine I have a table: ID field1 field2 — ——- —— 111 1 11113

  • 0

Imagine I have a table:

ID     field1       field2
---    -------      ------
111      1          11113
112      1          11114
113      1          44321
114      1          49339
115      2          53234

I’m interested in all records where field1 = 1 – and specifically field2 = 44321 , but I want to know what position it is in my selection of field1=1 (in this case, it’d be 3).

 SELECT * FROM table WHERE field1 = 1 ORDER BY id

will get me all the records I want, but what I want to know is the number 3 (the position in the selection that 44321 is – it’s the 3rd record in the query, I want to know that 3).

Is there any elegant query I can do to find out the position of the row I’m particularly interested in, or do I need to cursor fetch and walk through my recordset and find out with some counter++ business?

I know the field1 I want, I know the field2 I want – I just want to know what position field1+field2 is in the greater field1=1 query – that 3, the position).

  • 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-05-22T22:45:38+00:00Added an answer on May 22, 2026 at 10:45 pm

    Try this:

    POS column will give the position of the record that you are looking for

    WITH qry AS
    (
        SELECT a.* 
                     ROW_NUMBER() OVER(ORDER BY id)  POS
            FROM table a
         WHERE field1 = 1 
    )
    SELECT qry.pos
      FROM qry
     WHERE field2 = 44321 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine I have table like this: id:Product:shop_id 1:Basketball:41 2:Football:41 3:Rocket:45 4:Car:86 5:Plane:86 Now, this
Imagine I have a table which stores a series of sparse vectors. A sparse
Imagine you have a normal table view where each row is an item on
Imagine I have these columns in a table: id int NOT NULL IDENTITY PRIMARY
I have a problem. Imagine this data model: [Person] table has: PersonId, Name1 [Tag]
Imagine that I have a Customer table. And in this table is an ID
Imagine I have a database with one table, this table has only one field
Imagine that we have a poco that maps a table in a db. There
2 databases QF AND TK QF has the following: Imagine you have a table
Imagine you have a database table that stores a list of people. You want

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.