LIKE

Text patterns with LIKE

SQLite in your browser
Lesson concept What you'll do
1 / 4

Find titles that start with or contain some text.

LIKE with %, which stands for any characters.

The database
10 rows
book_idtitleauthorgenreyearpages
1The Fellowship of the RingJ.R.R. TolkienFantasy1954423
2The Great GatsbyF. Scott FitzgeraldFiction1925180
3Charlotte's WebE.B. WhiteChildren1952184
4DraculaBram StokerHorror1897418
5Pride and PrejudiceJane AustenRomance1813432
6The Girl with the Dragon TattooStieg LarssonThriller2005465
7Angels & DemonsDan BrownThriller2000616
8MockingjaySuzanne CollinsScience Fiction2010390
9Gone GirlGillian FlynnThriller2012419
10The Time MachineH.G. WellsScience Fiction1895118
Click a name to type it
Your query
 
Hint: click the green edit button on the board, or type it yourself
Query output Ready to run

Run your query to see the result table.

Press the green Run button or Ctrl+Enter.

Study notes

How LIKE works

  • What does LIKE do?

    WHERE title LIKE 'Harry Potter%'

    It compares text with a pattern instead of exact text. Use it after WHERE, where you'd otherwise write =.

  • What does % mean?

    Any text at all, including none. 'The%' starts with The, '%Girl' ends with Girl, '%Ring%' has "Ring" anywhere.

  • What does _ mean?

    Exactly one character. 'Emm_' matches Emma, but not Emmanuel.

  • Does LIKE care about capitals?

    In SQLite, not for A to Z: LIKE 'harry%' finds Harry Potter. Some databases do care; the table below shows which.

  • How is this like Excel?

    The same wildcards as COUNTIF and XLOOKUP's wildcard mode, with * written as % and ? written as _.

Other databases

How other databases do it

The lessons run on SQLite. Most of SQL is the same everywhere; these are the places where this lesson's SQL differs.

Does LIKE 'harry%' find Harry Potter?
DatabaseHowNote
SQLite (these lessons)YesLIKE ignores capitals for A to Z (not for accented letters).
PostgreSQLNoLIKE cares about capitals. ILIKE ignores them.
MySQL / MariaDBYesThe usual collations ignore capitals.
SQL ServerYesThe default collation ignores capitals.
OracleNoLIKE cares about capitals. Use UPPER(title) LIKE 'HARRY%'.
Sybase ASENoThe default binary sort order cares about capitals.
Extra pattern characters
DatabaseHowNote
SQLite (these lessons)% and __ stands for exactly one character. GLOB uses * and ? and cares about capitals.
PostgreSQL% and _SIMILAR TO and ~ give fuller patterns (regular expressions).
MySQL / MariaDB% and _REGEXP gives fuller patterns.
SQL Server% _ [ ][abc] matches one of a, b or c: LIKE '[A-C]%' starts with A, B or C.
Oracle% and _REGEXP_LIKE gives fuller patterns.
Sybase ASE% _ [ ][abc] matches one of a, b or c, as in SQL Server.

Know someone fighting with a spreadsheet? Send them this page.