ClickHouse/docs/en/sql-reference/statements/select/limit.md
Eugene Klimov 2a3292cf00
add ORDER BY ... WITH FILL, LIMIT... WITH TIES documentation to RU and EN locale (#12410)
* add ORDER BY ... WITH FILL documentation to RU and EN locale

Signed-off-by: Slach <bloodjazman@gmail.com>

* Update docs/en/sql-reference/statements/select/limit.md

* Update docs/en/sql-reference/statements/select/limit.md

* Update docs/ru/sql-reference/statements/select/order-by.md

* Update docs/en/sql-reference/statements/select/limit.md

* Update docs/en/sql-reference/statements/select/order-by.md

* Update docs/en/sql-reference/statements/select/order-by.md

* Update docs/en/sql-reference/statements/select/order-by.md

* Update docs/en/sql-reference/statements/select/order-by.md

* Update docs/en/sql-reference/statements/select/order-by.md

* Update docs/ru/sql-reference/statements/select/limit.md

Co-authored-by: Ivan Blinkov <github@blinkov.ru>
2020-07-14 00:52:40 +03:00

1.5 KiB

toc_title
LIMIT

LIMIT Clause

LIMIT m allows to select the first m rows from the result.

LIMIT n, m allows to select the m rows from the result after skipping the first n rows. The LIMIT m OFFSET n syntax is equivalent.

n and m must be non-negative integers.

If there is no ORDER BY clause that explicitly sorts results, the choice of rows for the result may be arbitrary and non-deterministic.

LIMIT ... WITH TIES modifier

When you set WITH TIES modifier for LIMIT n[,m] and specify ORDER BY expr_list, you will get in result first n or n,m rows and all rows with same ORDER BY fields values equal to row at position n for LIMIT n and m for LIMIT n,m.

This modifier also can be combined with ORDER BY ... WITH FILL modifier.

For example, the following query

SELECT * FROM (
    SELECT number%50 AS n FROM numbers(100)
) ORDER BY n LIMIT 0,5

returns

┌─n─┐
│ 0 │
│ 0 │
│ 1 │
│ 1 │
│ 2 │
└───┘

but after apply WITH TIES modifier

SELECT * FROM (
    SELECT number%50 AS n FROM numbers(100)
) ORDER BY n LIMIT 0,5 WITH TIES

it returns another rows set

┌─n─┐
│ 0 │
│ 0 │
│ 1 │
│ 1 │
│ 2 │
│ 2 │
└───┘

cause row number 6 have same value "2" for field n as row number 5