SQL LIKE Statement

The SQL LIKE statement is used with the LIKE operator and the WHERE clause to search for records with specific patterns in the column(s).

  • The SQL LIKE statement can be used to search for records with or without values starting with specific character(s)
  • The SQL LIKE statement can be used to search for records with or without values containing specific character(s)
  • The SQL LIKE statement can be used to search for records with or without values ending with specific character(s)

SQL LIKE statement with pattern

SELECT column_name(s)

FROM table_name

WHERE column_name LIKE pattern

SQL LIKE statement without pattern

SELECT column_name(s)

FROM table_name

WHERE column_name NOT LIKE pattern


Database Table “Members”

Id FirstName LastName Email City Phone
1 Gilbert Duncan [email protected] Newark 973-600-3300
2 Elvis Daniels [email protected] Piscataway 862-600-3050
3 Michael Green [email protected] Detroit 732-500-5050
4 Kelvin Graham [email protected] Detroit 732-555-5050
5 Arthur Owen [email protected] Toronto 416-300-0685

SQL LIKE Example

We want to return the records in the “Members” table with “Phone” starting with “732”

SELECT *

FROM Members

WHERE Phone LIKE ‘732%’

RESULT of SQL LIKE statement above will be

Id FirstName LastName Email City Phone
3 Michael Green [email protected] Detroit 732-500-5050
4 Kelvin Graham [email protected] Detroit 732-555-5050

The result above shows the records with “Phone” starting with “732”

We want to return the records in the “Members” table with “Phone” containing “600”

SELECT *

FROM Members

WHERE Phone LIKE ‘%600%’

RESULT of SQL TOP statement above will be

Id FirstName LastName Email City Phone
1 Gilbert Duncan [email protected] Newark 973-600-3300
2 Elvis Daniels [email protected] Piscataway 862-600-3050

The result above shows the records with “Phone” containing “600”

We want to return the records in the “Members” table with “Phone” ending with “050”

SELECT *

FROM Members

WHERE Phone LIKE ‘%050’

RESULT of SQL TOP statement above will be

Id FirstName LastName Email City Phone
2 Elvis Daniels [email protected] Piscataway 862-600-3050
3 Michael Green [email protected] Detroit 732-500-5050
4 Kelvin Graham [email protected] Detroit 732-555-5050

The result above shows the records with “Phone” ending with “050”

We want to return the records in the “Members” table without “Phone” containging “600”

SELECT *

FROM Members

WHERE Phone NOT LIKE ‘%600%’

RESULT of SQL TOP statement above will be

Id FirstName LastName Email City Phone
3 Michael Green [email protected] Detroit 732-500-5050
4 Kelvin Graham [email protected] Detroit 732-555-5050
5 Arthur Owen [email protected] Toronto 416-300-0685

The result above shows the records without “Phone” containing “600”