WEBVTT

00:00:00.350 --> 00:00:01.331
Welcome back!

00:00:01.511 --> 00:00:03.175
Here's what we'll learn in this lesson.

00:00:03.355 --> 00:00:05.979
Filter and sort using relationship paths.

00:00:06.159 --> 00:00:11.535
We will select invoices by customer city, order
by date, and combine conditions with

00:00:11.535 --> 00:00:12.239
parameters.

00:00:13.569 --> 00:00:15.276
Continue in the same console.

00:00:15.456 --> 00:00:19.061
We will use the customers and invoices we
imported last time.

00:00:19.241 --> 00:00:24.511
If Python was closed, the download includes a
script to rebuild that temporary dataset.

00:00:25.850 --> 00:00:27.727
Let's find invoices for Florence.

00:00:27.907 --> 00:00:29.635
Use the customer city in where.

00:00:29.815 --> 00:00:33.421
Colon city is a parameter: its value is passed
separately.

00:00:33.601 --> 00:00:35.734
We only ask to return the invoice number.

00:00:37.150 --> 00:00:38.899
Let's sort invoices by city.

00:00:39.079 --> 00:00:40.978
Use the same path in order by.

00:00:41.158 --> 00:00:43.547
Without a direction, the order is ascending.

00:00:43.727 --> 00:00:45.861
Limit keeps the displayed result short.

00:00:47.250 --> 00:00:48.957
Let's show the newest rows first.

00:00:49.137 --> 00:00:51.974
From an invoice row, follow its invoice to the
date.

00:00:52.154 --> 00:00:53.839
Add DESC for descending order.

00:00:54.019 --> 00:00:56.579
These three rows belong to the latest invoice.

00:00:57.950 --> 00:00:59.635
Now start from an invoice row.

00:00:59.815 --> 00:01:03.613
To reach the customer city, go through the
invoice and then the customer.

00:01:04.943 --> 00:01:06.585
Let's find rows for Florence.

00:01:06.765 --> 00:01:08.835
The filter follows two relationships.

00:01:09.015 --> 00:01:12.236
The returned columns follow the product relation
instead.

00:01:12.416 --> 00:01:15.317
A field used in a filter need not be selected.

00:01:16.700 --> 00:01:18.300
Let's combine the conditions.

00:01:18.480 --> 00:01:22.256
Keep Florence rows from October first, newest
invoices first.

00:01:22.436 --> 00:01:24.164
City and date are parameters.

00:01:24.344 --> 00:01:27.053
Neither filtered field needs to appear in the
result.

00:01:27.233 --> 00:01:30.241
The same paths work in columns, where, and order
by.

00:01:31.571 --> 00:01:33.385
Let's close this read transaction.

00:01:33.565 --> 00:01:37.063
We only read the data; the imported records have
not changed.

00:01:38.450 --> 00:01:39.943
Thanks for following along!

00:01:40.123 --> 00:01:43.409
Use relationship fields wherever the query needs
them.

00:01:43.589 --> 00:01:48.410
Select only what you want to read, and add just
the conditions and ordering you need.
