Pattern matching in SQL- Like Operator

by | Apr 7, 2024 | SQL | 0 comments

LIKE Operator:

The LIKE operator is used to search for a specified pattern in a column.

It allows the use of wildcards:

% (percent sign): Matches zero or more characters.

_ (underscore): Matches any single character.

Examples:

SELECT * FROM employees WHERE last_name LIKE 'Sm%': Finds employees with last names starting with “Sm”.

SELECT * FROM products WHERE product_name LIKE '%chair%': Finds products with names containing “chair” anywhere.

Case Insensitivity:

SQL pattern matching is case-sensitive by default, but you can use functions or modifiers to perform case-insensitive matching.

Example (MySQL):

SELECT * FROM employees WHERE last_name LIKE 'smith' COLLATE utf8_general_ci: Performs case-insensitive matching for last names equal to “smith”.

Written by HintsToday Team

Related Posts

Database Structures, Types of Keys

Learn about tables, fields (or attributes), records, keys and table relationships. What is database structure? A database structure is the blueprint that defines how data is arranged ,organized, stored, accessed, and managed within a database. It's the underlying...

read more

SQL Data Types(Numeric, String & Date)- Default Values

SQL (Structured Query Language) supports various data types to represent different kinds of data. These data types define the format and constraints of the data stored in each column of a table. Here are some common SQL data types: Numeric Types: INT: Integer type,...

read more

Get the latest news

Subscribe to our Newsletter

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *