🔍
👶 Kids📝 Blog About Contact 🚀 Get Started Free

SQL – Wildcards

Deep dive into SQL wildcard characters % and _ and how to use them in creative search patterns.

Wildcards are the pattern-matching characters used with the LIKE operator. They give SQL text search surprising flexibility without needing a full text-search engine. The % wildcard is like saying “anything” — zero or more of any character. The _ wildcard is like saying “exactly one mystery character.”

Combining wildcards lets you build precise patterns: '_a%' finds any string where the second character is ‘a’, regardless of what comes before or after. Real-world uses include searching for product codes, email domains, and partial names.

Creative wildcard combinations

'M%'       -- Starts with M
'%a'       -- Ends with a
'%en%'     -- Contains "en"
'__a%'     -- Third char is 'a'
'M_____'   -- 6-char string starting with M

Try It Yourself — Interactive SQL Editor

Edit the query below and click Run Query ▶ to see live results powered by SQLite running directly in your browser.

SQLite – edit & run
Results
← Click Run Query ▶ to see results

Key Points

  • % = zero or more of any character
  • _ = exactly one of any character
  • Escape literal % or _ with ESCAPE clause when searching for them
  • LIKE with only % is equivalent to IS NOT NULL and not empty

Pro Tip from CodesCompiler: The best way to learn SQL is to break things intentionally — modify the query above, change the WHERE conditions, try different columns. Every error teaches you something the docs cannot.

In the next lesson, we continue exploring SQL’s powerful feature set to build your database mastery.