From customer limit 5; customer id


Download 19.59 Kb.
bet1/4
Sana17.01.2023
Hajmi19.59 Kb.
#1097970
  1   2   3   4
Bog'liq
Exercise dvdrental


Exercise
Select the film_id and title columns from the film table.
LIMIT
Instead of getting all rows, we can specify a limit of the number of rows to retrieve.
SELECT customer_id, store_id, first_name, last_name
FROM customer
LIMIT 5;
customer_id | store_id | first_name | last_name
-------------+----------+------------+-----------
524 | 1 | Jared | Ely
1 | 1 | Mary | Smith
2 | 1 | Patricia | Johnson
3 | 1 | Linda | Williams
4 | 2 | Barbara | Jones
(5 rows)
Here, we got all of the output on a single page, and we can see the row count output at the end.
The order of the rows is not random, but it is not guaranteed to be in any particular order by default either. The order can change over time, and it is affected by which rows have been accessed recently.
Exercise
Select 5 rows from the film table, getting all of the columns.
OFFSET
We can skip rows that would normally be at the beginning of the result set with offset. This is useful usually when we sort the result set in a particular order, something we’ll get to later.
SELECT customer_id, store_id, first_name, last_name
FROM customer
LIMIT 5
OFFSET 10;
customer_id | store_id | first_name | last_name
-------------+----------+------------+-----------
10 | 1 | Dorothy | Taylor
11 | 2 | Lisa | Anderson
12 | 1 | Nancy | Thomas
13 | 2 | Karen | Jackson
14 | 2 | Betty | White
(5 rows)
WHERE
Instead of getting all rows or a specific number of rows, we can also specify which rows we want by specifying conditions on the values of particular columns (e.g. equals, greater than, less than).
For example, we can select rows from customer that have a store_id=2 with:

Download 19.59 Kb.

Do'stlaringiz bilan baham:
  1   2   3   4




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling