27 Ocak 2019 Pazar

ORDER BY + LIMIT + OFFSET

ORDER BY Nedir?
Order by kullanılmazsa veri tabanı sonucu istediği şekilde sıralayarak döndürür. Açıklaması şöyle.
After a query has produced an output table (after the select list has been processed) it can optionally be sorted. If sorting is not chosen, the rows will be returned in an unspecified order. The actual order in that case will depend on the scan and join plan types and the order on disk, but it must not be relied on. A particular output ordering can only be guaranteed if the sort step is explicitly chosen.
Bir başka açıklama şöyle
If ORDER BY is not given, the rows are returned in whatever order the system finds fastest to produce.
LIMIT Nedir
Açıklaması şöyle
To limit the result, Postgres uses limit ... (SQL-server uses TOP keyword)
Örnek
Şöyle yaparız.
SELECT rental_duration FROM films
  ORDER BY length
  LIMIT 5 OFFSET 498 AS A

Hiç yorum yok:

Yorum Gönder