Finding Data that Matches a Pattern2:43 with Andrew Chalkley
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.
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>;
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
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