Solved

# value of field in position n

Posted on 2012-03-23
253 Views
Hi there,

Let´s say I have a table XYZ with 2 fields and 3 records, say:

field1   field2
1               car
32             dog
123           cat

I want to select 'cat' with an SQL statement like:

"select field2  from tableXYZ where field1 = [value of field1 in n-row] order by field1 asc"

My question is: how should I "fill the bold place", please?

(I want  a general solution to this case, in which I am able to find which is the number present in the record of field1 when we are looking at the n-th row, where n is given.)

Thanks,
fskilnik.
0
Question by:fskilnik
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 4
• 2

LVL 18

Expert Comment

ID: 37757299
What do you mean the "nth" row?  is n the value of field1?  I'm guessing not but if so, it would just be n for your bold area:
select field2  from tableXYZ where field1 =n order by field1 asc

If n refers to an ID column in your table it would work like this
select field2  from tableXYZ where ID = n
0

Author Comment

ID: 37758801
The problem refers to your second interpretation (of course), but your suggestion does not work, because there is NO "ID" column with this name, although I WANT to do what you suggested... in other words, the problem is how to use the number of the line if the counter óf the number of the line involved is not a field itself... I hope you understood my difficulty.
0

Accepted Solution

fskilnik earned 0 total points
ID: 37759228
I was looking at an "SQL array"... and I found the question and the solution at this EE link.

Thank you anyway.
fskilnik.
0

LVL 18

Expert Comment

ID: 37759843
Ah, and therein lies the problem with EE.  My effort is provided without cost to EE or the poser of the question.
0

Author Comment

ID: 37761197
@UnifiedIS: I am really surprised with your complaint, because I have been here at EE for many many years and your first reply showed me you took VERY little time even to understand my question (in my opinion), what is something ENORMOUSLY UNUSUAL in my EE experience, by the way.

(Sometimes I would like to give 5,000 points to the experts, not only the 500 permitted. It was certainly not the case here, simply because I could see no use to the "solution" you have provided.)

Even so, if you would like to (and if the moderator agrees), I would be glad to give you the 500 points as a compensation to your effort (your word, no pun-intended).
0

Author Closing Comment

ID: 37775759
(I guess I found the solution myself.)
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
###### Suggested Courses
Course of the Month5 days, 15 hours left to enroll