[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Return a row in a select statement

Posted on 2006-04-26
7
Medium Priority
?
343 Views
Last Modified: 2012-05-05
I have a table tbExample with 100 rows. I want to get the row 29. How can I do that with select statement. Something like this:
SELECT * FROM TBEXAMPLE WHERE POSITIONOFROW = 29
0
Comment
Question by:maidinhtai
7 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 16541886
Hi maidinhtai,
What database ?
You will appreciate that this type of selection will not produce the same answer every time you run it.

Pete
0
 
LVL 3

Author Comment

by:maidinhtai
ID: 16541897
Hi Peter57r,
It's a MS  SQL server database. Everytime I run this select statement, it will return the same result.
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 1200 total points
ID: 16541953

SELECT TOP 1 *  With Ties
From urTable E
LEFT OUTER JOIN
(SELECT TOP 28 * WITH Ties FROM YourTable )T
ON E.primaryKey = T.PrimaryKey
WHERE T.PrimaryKey IS NULL
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 16541962
or

SELECT * FROM urTable A WHERE 29 = (SELECT Count(*) FROM urTable B WHERE A.primaryKey = B.PrimaryKey )
0
 
LVL 3

Author Comment

by:maidinhtai
ID: 16542008
aneeshattingal,
      What is 'With ties' used for? Why do I have to put it into the select statement
0
 
LVL 4

Assisted Solution

by:nguyenvinhtu
nguyenvinhtu earned 800 total points
ID: 16542018
SELECT * FROM TBEXAMPLE A
WHERE (SELECT COUNT(*) FROM TBEXAMPLE B WHERE B.COL <= A.COL) = 29

-- Above code always return line 29 of TBEXAMPLE however many column there are in TBEXAMPLE
-- COL is a column name of TBEXAMPLE, you can choose any
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 16542107
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question