---
title: "How do you use the LIKE operator with wildcard characters (%) to perform pattern matching in SQL?"  
description: "How do you use the LIKE operator with wildcard characters (%) to perform pattern matching in SQL?"  
author: "Revati S Misra"  
published: 2023-06-30  
updated: 2023-07-01  
canonical: https://www.mindstick.com/forum/158912/how-do-you-use-the-like-operator-with-wildcard-characters-to-perform-pattern-matching-in-sql  
category: "mssql server"  
tags: ["mssql server", "sql server", "sql"]  
reading_time: 3 minutes  

---

# How do you use the LIKE operator with wildcard characters (%) to perform pattern matching in SQL?

How do you use the LIKE [operator](https://www.mindstick.com/blog/144/union-intersection-and-except-operator-in-sql-server) with [wildcard](https://www.mindstick.com/interview/33955/why-is-the-sql-wildcard-like-operator-in-the-query) [characters](https://answers.mindstick.com/qa/42112/who-is-the-originator-of-avengers-characters) (%) to perform [pattern matching](https://www.mindstick.com/articles/1865/pattern-matching-in-erlang) in [SQL](https://www.mindstick.com/articles/13115/types-of-keys-in-sql-or-oracle-database)?

## Replies

### Reply by Aryan Kumar

The LIKE operator in SQL is used to perform [pattern](https://www.mindstick.com/forum/2314/what-is-the-mvp-and-mvc-pattern) matching. It can be used with wildcard characters to match any number of characters, any single character, or a specific range of characters.

The two most commonly used wildcard characters are:

- `%` - Matches zero or more characters.
- `_` - Matches one single character.

For example, the following query will return all rows from the `products` table where the product name starts with the letter "A":

SQL

```plaintext
SELECT *
FROM products
WHERE product_name LIKE 'A%';
```

The `%` wildcard character matches zero or more characters, so this query will return all products that start with the letter "A", regardless of how many other characters are in the name.

The following query will return all rows from the `products` table where the product name contains the letter "a":

SQL

```plaintext
SELECT *
FROM products
WHERE product_name LIKE '%a%';
```

The `%` wildcard character can be used anywhere in the pattern, so this query will return all products that contain the letter "a", regardless of where it is in the name.

The `_` wildcard character matches one single character, so the following query will return all rows from the `products` table where the product name starts with the letter "A" and ends with the letter "s":

SQL

```plaintext
SELECT *
FROM products
WHERE product_name LIKE 'A_s';
```

The `_` wildcard character can only be used once in a pattern, so this query will only return products that match the exact pattern specified.

The LIKE operator can also be used with other wildcard characters, such as `[]`, which matches any single character in a specified set. For example, the following query will return all rows from the `products` table where the product name starts with the letter "A" and ends with a digit:

SQL

```plaintext
SELECT *
FROM products
WHERE product_name LIKE 'A[0-9]';
```

The `[0-9]` wildcard character matches any single digit, so this query will return all products that match the exact pattern specified.

The LIKE operator is a powerful tool that can be used to perform pattern matching in SQL. By using wildcard characters, you can match any number of characters, any single character, or a specific range of characters. This can be used to find specific rows in a table or to filter results based on a pattern.


---

Original Source: https://www.mindstick.com/forum/158912/how-do-you-use-the-like-operator-with-wildcard-characters-to-perform-pattern-matching-in-sql

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
