Writing a specific query involving primary keys in SQL

Tags:
Primary keys
Query
SQL
SQL Query
I need to write a query in SQL that will get the fifth-from-last record from my database when either a primary key is defined or no primary at all is defined. How would this query look?

Answer Wiki

Thanks. We'll let you know when a new response is added.

You can use a query something like this to get the result you are looking for.
<pre>
SELECT TOP 1*
FROM (
SELECT TOP (5) *
FROM YourTable
ORDER BY SomeColumn DESC
) a
ORDER BY SomeColumn ASC</pre>

SomeColumn is what ever column, or columns you need to use in order to get the values in the table in the correct order. It can be an integer, datetime, etc.

I have used this link for reference as well

http://www.w3schools.com/SQL/sql_intro.asp

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following