Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The last 3 rows in a select... 2

Status
Not open for further replies.

Vivianez

Programmer
Oct 10, 2001
25
BR
How can I get the 3 last rows in a select?
 
You'd first need to ORDER BY some sort of criteria. If you want the LAST THREE rows, maybe you can ORDER BY the opposite way you're ordering now.

For example

[tt]SELECT * FROM table_name ORDER BY id ASC[/tt]

Change it to

[tt]SELECT TOP 3 * FROM table_name ORDER BY id DESC[/tt]

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
top 3 was what I needed!!! Thanks!
Is there an opposite for top?
 
The opposite of TOP 3 would be, like I said, reversing your SORT function and still taking the top 3.

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top