liveBook · Manning

Wildcard

As explained in Learn SQL in a Month of Lunches

A percent wildcard (%) is an SQL pattern-matching character that matches any sequence of characters, including an empty string.

Use the percent wildcard (%) when a query must find a text pattern rather than an exact value. It matches any sequence of characters, including no characters, and works with LIKE. section 7.1 section 7.1.1

Find last names beginning with S

SELECT FirstName, LastName FROM author WHERE LastName LIKE 'S%'; Read 'S%' as “S and something.” The something may contain many characters or none, so the pattern finds names that start with S. section 7.1.1

SELECT
    FirstName,
    LastName
FROM author
WHERE LastName LIKE 'S%';

View the complete query for matching author last names that begin with S. section 7.1.1

Place % wherever the unmatched part of the text may occur:

  • Use LastName LIKE '%N' to find last names ending in N. section 7.1.1
  • Use LastName LIKE 'M%N' to find last names beginning with M and ending with N. section 7.1.1
  • Use LastName LIKE '%DE%' to find last names containing DE anywhere. section 7.1.1

LIKE signals that the quoted value is a pattern. Replacing LIKE with = does not perform wildcard matching. For a single unknown character, use _, which can be combined with %; wildcard support beyond these symbols varies by database system. section 7.1.1 section 7.1.2

How Learn SQL in a Month of Lunches covers it

How deep it goes
Explains percent matching, LIKE syntax, placement patterns, and the distinction from single-character underscore matching.
Examples
Demonstrates author-name searches for prefixes, suffixes, bounded patterns, and contained text.
What it assumes
Assumes basic SQL filtering and teaches wildcard pattern matching through familiar spoken descriptions of search intent.
What you can do after
Apply it via SQL LIKE to search text columns for flexible character patterns.
How it connects
Connects wildcard matching with SQL LIKE, string filtering, exact comparison, and the underscore wildcard.

Also explained in

Compare how 8 books explain wildcard →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn SQL in a Month of Lunches. The section links point to the parts of the book it draws on.