You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs-parts/queries/03-Fetch_lang1.rst
+19Lines changed: 19 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,6 +35,25 @@ Primary key values
35
35
36
36
``KEY`` can also used when returning attribute values as separate variables, such that one of the returned variables contains the entire primary keys.
37
37
38
+
Sorting and limiting the results
39
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
40
+
41
+
To sort the result, add the additional ``order_by`` argument to ``fetch`` .
42
+
43
+
.. code-block:: python
44
+
45
+
data = query.fetch(order_by='name')
46
+
47
+
The ``order_by`` argument is passed directly to SQL and follows the same syntax as the `ORDER BY clause <https://dev.mysql.com/doc/refman/5.7/en/order-by-optimization.html>`_
48
+
49
+
Similarly, the LIMIT and OFFSET clauses can be used to limit the result to a subset of entities.
50
+
51
+
For example, one could do the following:
52
+
53
+
.. code-block:: python
54
+
55
+
data = query.fetch(order_by='name', limit=10, offset=5)
0 commit comments