473,408 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

LIMIT in MS SQL ??!!

hi,

I have a question.
Maybe You know the equivalent to command LIMIT from MySQL
I couldn`t find something like this in MS SQL
PS
I try to display 10 records begining form e.g. 4 sort by id
something like: "SELECT * FROM table WHERE name=... LIMIT 4, 10 ORDER BY id"
in MySQL

thanx,
Urban
Jul 20 '05 #1
2 18087
Hello!

Please see the TOP command in your Books on-line... select top 10 * from
table ...

Cheers,
Dejan
"Urban" <kl******@tlen.pl> wrote in message
news:co**********@news.zigzag.pl...
| hi,
|
| I have a question.
| Maybe You know the equivalent to command LIMIT from MySQL
| I couldn`t find something like this in MS SQL
| PS
| I try to display 10 records begining form e.g. 4 sort by id
| something like: "SELECT * FROM table WHERE name=... LIMIT 4, 10 ORDER BY
id"
| in MySQL
|
| thanx,
| Urban
|
|
Jul 20 '05 #2
"Urban" <kl******@tlen.pl> wrote in message news:co**********@news.zigzag.pl...
hi,

I have a question.
Maybe You know the equivalent to command LIMIT from MySQL
I couldn`t find something like this in MS SQL
PS
I try to display 10 records begining form e.g. 4 sort by id
something like: "SELECT * FROM table WHERE name=... LIMIT 4, 10 ORDER BY id"
in MySQL

thanx,
Urban


Say you have table T with a column C whose values are returned
in the order given by <column order> and, given this order, you'd
like N rows starting from row S. The MySQL query is:

SELECT C
FROM T
ORDER BY C <column order>
LIMIT S, N

Note that the initial row with the LIMIT clause is 0, not 1.

In T-SQL, one can write the following using the product-specific
TOP clause:

SELECT TOP N C
FROM (SELECT TOP S + N C
FROM T
ORDER BY C <column order>) AS TopN(C)
ORDER BY C <opposite column order>

For example, the MySQL code

SELECT C
FROM T
ORDER BY C DESC
LIMIT 5, 10

orders column C in descending order and returns 10 rows
from row 6 to 15. This can be can be written in T-SQL by
plugging into the above to get

SELECT TOP 10 C
FROM (SELECT TOP 15 C
FROM T
ORDER BY C DESC) AS TopN(C)
ORDER BY C ASC

Obviously, the one-argument version of LIMIT, e.g.,

SELECT C
FROM T
ORDER BY C <column order>
LIMIT N

is simply the following in T-SQL:

SELECT TOP N C
FROM T
ORDER BY C <column order>

--
JAG
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Afkamm | last post by:
Hi, :) The preg_replace function... preg_replace(pattern, replacement, subject ) How on earth do you get the limit value to work with arrays? In my code both the pattern and replacement...
3
by: CajunCoiler \(http://www.cajuncoiler.tk\) | last post by:
I've seen no reference to this in the MSDN library, so I ask here... what is the known upper limit for the RichTextbox control? And when this limit is exceeded, what error is generated?
3
by: Jay K | last post by:
Hi, I have multiple queries like this: SELECT col1, col2, col3, col4 FROM table1, table2 where table1.col1 = table2.col1 and table1.col2 = 1 ORDER BY col3 desc LIMIT 5 and
4
by: emily_g107 | last post by:
Hi, I need to limit results in the following query type: ...
0
by: D. Dante Lorenso | last post by:
I need to know that original number of rows that WOULD have been returned by a SELECT statement if the LIMIT / OFFSET where not present in the statement. Is there a way to get this data from PG ?...
2
by: elein | last post by:
Yes, I vacuumed. Reproduced on both 7.3.2 and 7.5. Brain dead java beans want order by clauses in views that they use. my view is: select .... from bigtable b left join lookuptable l order...
4
by: Bill | last post by:
Hi, I would be grateful if someone could clarify my rather confused ideas of the 10 connection limit on XP/2000 when its being used as a server. (I realise that XP is really a client op sys with...
1
by: lawrence k | last post by:
Want to replace the limit clause in a query, but can't get it right. What's wrong with this: $pattern = "(.*)limit (.*)"; $replacement = '$1'; $replacement .= "LIMIT $limit"; $replacement .=...
3
by: sadanjan | last post by:
Hi , Appreciate if someone can clarify if database Share Memory Limit (2 GB ) in Unix 32 bit boxes is the top limit for all the databases put together in a database or is it for each of the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.