Forums

This topic is locked

SQL - how to select top 100 rows?

Posted 12 Jun 2006 18:49:28
1
has voted
12 Jun 2006 18:49:28 Michael D'Ambrosio posted:
I taught myself SQL about a year ago by reviewing queries put together by my company's MIS team, but anytime I need to do something new I don't know where to learn it. I was looking for a good forum specifically for SQL so here I am.

My question - How can I select the first "n" rows in a table, and how can I select the last "n" rows in a table. For the latter part, assume I don't know the total rows, I just want to grab the last 500 or so?

Second question, can anyone recommend a forum for SQL that has a lot of activity?

Thanks

Replies

Replied 06 Jul 2006 15:08:23
06 Jul 2006 15:08:23 Roddy Dairion replied:
May be its too late but never came across this before. But here a little tip for you. Lets you have to get the last 500 rows in a table what you do is you sort your table DESC then put LIMIT 500. LIMIT Can be use as so LIMIT 500 this will take default order of the table and return the first 100 row. If you add to this ORDER BY FIELDNAME LIMIT 100 put it in the FIELDNAME in the order that you've asked and return the 1st 100 rows. LIMIT 100,500 this will skip the 1st 100 rows and return the next 500.

Edited by - roders22 on 06 Jul 2006 15:09:25
Replied 10 Jul 2006 18:19:41
10 Jul 2006 18:19:41 Patrick Woldberg replied:
LIMIT can be used on MySQL, for example: SELECT * FROM Table LIMIT 100

When using MSSQL you should use TOP 100, for example: SELECT TOP 100 * FROM Table

--------------------------------------------------
Patrick Woldberg
Web Developer at Dynamic Zones
Administrator at DMXzone.com, FLzone.net, FWzone.net and DNzone.com
--------------------------------------------------
Replied 11 Jul 2006 17:43:54
11 Jul 2006 17:43:54 Janusz Jasinski replied:
SELECT TOP 100 Whatever
FROM Table???

[Win XP] • [Windows 2003 Server] • [SuSE 9.2 Pro] • [FreeBSD 5.3] • [Macromedia Studio 2004] • [ASP.NET] • [ASP] • [PHP] • [C#] • [(DH)(XH)(HT)(X)ML] • [CSS] • [VB] • [Java] • [Making Lasagne]

Reply to this topic