This is a forum where members new and old can come to ask questions and get info and opinions. It is not a place to advertise your business or have other forms of advertising, whether it be in your posts or signature.

All links in the forum will not be indexed by Search Engines and any unapproved forms of advertising or spam will be dealt with accordingly, deleted, and that member's account banned.

Forums

Overview » SQL and Databases » SQL - how to select top 100 rows?
Reply

SQL - how to select top 100 rows?

Michael D'Ambrosio
Newbie



Since: 12 Jun 2006
Posts: 1
Posted 12 Jun 2006 18:49:28

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

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
Roddy Dairion
Moderator



Since: 12 Oct 2005
Posts: 444
Replied 06 Jul 2006 15:08:23
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
Patrick Woldberg
Official Representative



Since: 11 Feb 2003
Posts: 1,904
Replied 10 Jul 2006 18:19:41
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
--------------------------------------------------
Janusz Jasinski
Member



Since: 19 May 2004
Posts: 62
Replied 11 Jul 2006 17:43:54
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

Message
Reply
Follow us on Facebook Follow us on twitter Subscribe to the RSS feed
Activate your free membership today | Login | Currency