Solved

limit results MSSQL and PHP

Posted on 2007-11-30
4
480 Views
Last Modified: 2013-12-13
Is there a "LIMIT" when using php with MSSQL?  I am trying to get 10 results a time.  

First query 1-10, next query 11-20, etc.
I know with MySQL I can use LIMIT, but that doesn't seem to work with MS SQL query.

Thanks,
0
Comment
Question by:James Stone
  • 2
4 Comments
 
LVL 7

Expert Comment

by:Wod
ID: 20386054
SELECT TOP 10 * FROM Users
0
 
LVL 21

Accepted Solution

by:
nizsmo earned 500 total points
ID: 20386063
0
 
LVL 7

Expert Comment

by:Wod
ID: 20386065
or something like this would probably work better (ie: to get 11-20)

DECLARE @rowsperpage INT

DECLARE @start INT

SET @start = 120000
SET @rowsperpage = 10

SELECT * FROM
(
SELECT row_number() OVER (ORDER BY column) AS rownum, column2, column3, .... columnX
FROM   table) AS A
WHERE A.rownum BETWEEN (@start) AND (@start + @rowsperpage)
0
 

Author Closing Comment

by:James Stone
ID: 31412055
Thanks for the help - it works beautifully!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

726 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