---
title: "What is the SQL LIKE operator, and how can it be used for pattern matching in search queries?"  
description: "What is the SQL LIKE operator, and how can it be used for pattern matching in search queries?"  
author: "Revati S Misra"  
published: 2023-10-09  
updated: 2023-10-10  
canonical: https://www.mindstick.com/forum/160079/what-is-the-sql-like-operator-and-how-can-it-be-used-for-pattern-matching-in-search-queries  
category: "mssql server"  
tags: ["sql server", "sql"]  
reading_time: 2 minutes  

---

# What is the SQL LIKE operator, and how can it be used for pattern matching in search queries?

What is the [SQL](https://www.mindstick.com/articles/13115/types-of-keys-in-sql-or-oracle-database) LIKE [operator](https://www.mindstick.com/blog/144/union-intersection-and-except-operator-in-sql-server), and how can it be used for [pattern matching](https://www.mindstick.com/articles/1865/pattern-matching-in-erlang) in [search queries](https://www.mindstick.com/forum/160080/what-is-the-difference-between-the-sql-where-clause-and-the-having-clause-in-search-queries)?

## Replies

### Reply by Aryan Kumar

The SQL **LIKE** operator is used for [pattern](https://www.mindstick.com/forum/2314/what-is-the-mvp-and-mvc-pattern) matching in [search](https://www.mindstick.com/articles/65368/best-smo-services-company-in-hyderabad-improve-search-rankings) [queries](https://www.mindstick.com/forum/33678/sub-queries-in-sql-server). It allows you to search for data in a column that matches a specified pattern, which can include wildcard characters. The two main wildcard characters used with the **LIKE** operator are **%** and **_**.

Here's how the **LIKE** operator works:

- **%** **(Percentage Sign):** This wildcard represents any sequence of characters (including zero characters).
- **_ (Underscore):** This wildcard represents a single character.

Here are some common uses of the **LIKE** operator for pattern matching in search queries:

## Using % for Wildcard Matching:

- To find values that start with a specific pattern, use **%** at the end of the pattern.
- To find values that end with a specific pattern, use **%** at the beginning of the pattern.
- To find values that contain a specific pattern anywhere within them, use **%** at both ends of the pattern.
- Example:

```plaintext
-- Find all employees whose names start with "John"
SELECT * FROM employees WHERE name LIKE 'John%';

-- Find all products with "Widget" anywhere in their name
SELECT * FROM products WHERE product_name LIKE '%Widget%';
```

## Using _ for Single-Character Matching:

- To find values with a specific character at a particular position, use **_** in place of that character.
- Example:

```plaintext
-- Find all two-letter country codes where the second letter is "A"
SELECT * FROM countries WHERE country_code LIKE '_A%';
```

The **LIKE** operator is versatile and allows you to perform flexible pattern matching searches in SQL. It's especially useful when you need to search for data based on partial or approximate patterns in text or string columns.


---

Original Source: https://www.mindstick.com/forum/160079/what-is-the-sql-like-operator-and-how-can-it-be-used-for-pattern-matching-in-search-queries

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
