2
Reply

What is SQL LIKE operator ?

Raj Bhatt

Raj Bhatt

2y
7.7k
0
Reply

The SQL LIKE operator is used in a WHERE clause to search for a specified pattern in a column.
It allows you to search for data that matches a specified pattern
The pattern can include two wildcard characters:

  1. % (percent sign) - matches zero, one, or multiple characters
  2. _ (underscore) - matches a single character
  1. SELECT * FROM employees
  2. WHERE name LIKE 'R%';

Query Will Search Name From Employees Table That Start With β€œR” And Return All Name Start With β€œR”

  1. SELECT * FROM employees
  2. WHERE name LIKE '%R';

Query Will Search Name From Employees Table That End With β€œR” And Return All Name End With β€œR”

  1. SELECT * FROM employees
  2. WHERE name LIKE '%R%';

Query Will Search Name From Employees Table That Have β€œR” In Any Position And Return All Name Having β€œR” In Any Position

  1. SELECT * FROM employees
  2. WHERE name LIKE '%A_';

Query Will Search Name From Employees Table Second Last Letter Of Name Is β€œA” Return All Name Which Having Second Last Letter With β€œA”

    The SQL LIKE operator is used in a WHERE clause to match a specified pattern in a column of a table. It is often used with wildcard characters such as β€œ%” to represent any sequence of characters, or β€œ_” to represent any single character. The syntax for the LIKE operator is as follows:

    1. SELECT column_name
    2. FROM table_name
    3. WHERE column_name LIKE pattern;

    For example, the following query returns all rows from the β€œcustomers” table where the β€œcity” column starts with β€œLondo”:

    1. SELECT * FROM customers
    2. WHERE city LIKE 'Londo%';

    The SQL LIKE condition allows you to use wildcards to perform pattern matching in a query. The LIKE condition is used in the WHERE clause of a SELECT statement.