Sobes.tech
Junior — Middle

Selgitage LIKE funktsiooni SQL-is ja kuidas seda kasutatakse andmete otsimiseks

sobes.tech AI

Vastus AI-lt

In SQL, the LIKE operator is used to search for strings that match a specified pattern. It is often used in the WHERE clause to filter data based on partial matches.

The main wildcard characters are:

  • % — matches any number of characters (including zero).
  • _ — matches exactly one character.

Example of usage:

SELECT * FROM Employees
WHERE Name LIKE 'A%';

This query will select all employees whose names start with the letter "A".

Another example:

SELECT * FROM Products
WHERE Code LIKE '_123%';

Here, products are selected where the second, third, and fourth characters are "123", and the first can be any character.

Thus, LIKE allows flexible pattern-based data searching, which is useful when working with text fields.