- [Instructor] Now, you can customize your query results
by looking for records or rows in tables
that meet certain search criteria or selection criteria.
So here, we have an example with a multi-line Python string
representing a SQL query.
The SQL query is going to select the title,
edition and copyright columns from our titles table,
and we're only going to select them for the rows
that match copyright greater than the value 2016.
So we want basically any books published 2017 or later.
We did this as a triple quoted string
because we're breaking it apart
in multiple lines for readability,
and again we supply the same connection object
we created a couple of videos ago.
So as you can see here, what we are getting
as a result are only the books
that have copyright 2017 and higher.
Now, we can also do pattern matching in our where clause.
So in this next query, we're going to select the id,
first name and last name from the authors table
but we only want to select a given row
if the last name looks like the string that you see here,
which starts with the letter D,
followed by the %*, which means zero
or more additional characters.
So basically, any last name that starts
with the letter D will be a match
and in this case we're going to use
the same connection object and we chose to use
as our index on the left side of the display
of the pandas data frame that we're going
to get here the id column once again.
So if I go ahead and execute that
we can see that the ids are one, two and three
for Paul, Harvey and Abbey Deitel
in this particular database.
Now, that was to match zero or more characters.
You can match any specific character using the underscore
in your where clause for pattern matching
with that same like operator.
So here once again, we're going to select
the same id, first and last columns from the authors table
and this time we only want to select them
if the first name is like something
that starts with any character followed by
the letter B and then any number
of additional characters after that.
So basically, the second letter is B
and everything else can be pretty much anything you want.
So if I execute this, you can see
that there's only one author
whose first name has the second letter B.
We have one letter before that which is A
that matters the underscore,
and everything else after that matches the percent,
so it could of just been Ab or it could be Ab
and several additional letters in that case.