Solved

limit results MSSQL and PHP

Posted on 2007-11-30
4
479 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Title # Comments Views Activity
PHP AJAX JSON 2 75
Custom Wordpress Loop 22 38
Wordpress Security 29 46
Ajax and PHP 4 29
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 …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

792 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