Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
You don't have to be that specific when searching a database table. You can use patterns of characters to help find those trickier bits of data you're trying to track down.
SQL Used
Placing the percent symbol (%
) any where in a string in conjunction with the LIKE
keyword will operate as a wildcard. Meaning it can be substituted by any number of characters, including zero!
SELECT <columns> FROM <table> WHERE <column> LIKE <pattern>;
Examples:
SELECT title FROM books WHERE title LIKE "Harry Potter%Fire";
SELECT title FROM movies WHERE title LIKE "Alien%";
SELECT * FROM contacts WHERE first_name LIKE "%drew";
SELECT * FROM books WHERE title LIKE "%Brief History%";
PostgreSQL Specific Keywords
LIKE
in PostgreSQL is case-sensitive. To case-insensitive searches do ILIKE
.
SELECT * FROM contacts WHERE first_name ILIKE "%drew";
See all of the SQL used in SQL Basics in the SQL Basics Cheat Sheet.
You need to sign up for Treehouse in order to download course files.
Sign up