0

What's the the SQL Server equivalent of the following MYSQL query:

SELECT id FROM products WHERE id= '$this->idLIMIT 0, 10

LeeTee
  • 6,401
  • 16
  • 79
  • 139
  • Why blindly use NOLOCK? http://stackoverflow.com/questions/7123036/is-there-a-way-to-get-different-results-for-the-same-sql-query-if-the-data-stays/7123084#7123084 or http://stackoverflow.com/questions/3879822/is-nolock-the-default-for-select-statements-in-sql-server-2005/3879846#3879846 – gbn Nov 21 '11 at 12:46

3 Answers3

3

To handle limit 10,20

*Important Use 'ORDER BY'

SELECT TOP 20 FROM products WHERE id NOT IN(SELECT TOP 10 id FROM products ORDER BY id) ORDER BY id
3
SELECT * FROM ( 
    SELECT id, ROW_NUMBER() OVER (ORDER BY id) as row  
        FROM products where myparam='shopkeeper'
) a WHERE a.row > 0 and a.row <= 10
Royi Namir
  • 144,742
  • 138
  • 468
  • 792
1

You can use TOP 10 in MSSQL:

SELECT TOP 10 id FROM products WITH(NOLOCK) WHERE shopkeeper = '$this->shopkeeper'

If you need from 10-20, you'll need Royi's answer.

pritaeas
  • 2,073
  • 5
  • 34
  • 51