LIKE Operator

LIKE operatori `WHERE` klauzasida ustunda belgilangan shablon bo'yicha qidiruv o'tkazish uchun ishlatiladi.

SU

SQL LIKE Operator

LIKE operatori WHERE klauzasida ustunda belgilangan shablon bo'yicha qidiruv o'tkazish uchun ishlatiladi.

Wildcardlar

LIKE operatori bilan birga ishlatiladigan ikki ta'rifdagi wildcard mavjud:

  • % — nol, bitta yoki bir nechta belgilarni ifodalaydi.
  • _ — bitta belgini ifodalaydi.

Sintaksis

SELECT column1, column2, ...
FROM table_name
WHERE columnN LIKE pattern;

Demo Ma'lumotlar Bazasi

Quyidagi jadval Customers jadvalidan olingan:

CustomerIDCustomerNameContactNameAddressCityPostalCodeCountry
1Alfreds FutterkisteMaria AndersObere Str. 57Berlin12209Germany
2Ana Trujillo Emparedados y heladosAna TrujilloAvda. de la ConstituciónMéxico D.F.05021Mexico
3Antonio Moreno TaqueríaAntonio MorenoMataderos 2312México D.F.05023Mexico
4Around the HornThomas Hardy120 Hanover Sq.LondonWA1 1DPUK
5Berglunds snabbköpChristina BerglundBerguvsvägen 8LuleåS-958 22Sweden

% Wildcard

% wildcardi har qanday sonli belgilarni ifodalaydi, nol belgini ham.

Misol: L harfi bilan boshlangan shaharlar:

SELECT * FROM Customers
WHERE City LIKE 'L%';

_ Wildcard

_ wildcardi bitta belgi ifodalaydi.

Misol: L harfi bilan boshlangan va nd bilan tugagan shaharlar:

SELECT * FROM Customers
WHERE City LIKE 'L_nd';

Shartlar Qo'shish

Bir nechta shartlarni birlashtirish uchun AND yoki OR operatorlaridan foydalaning.

Misol: a yoki b harfi bilan boshlangan barcha mijozlar:

SELECT * FROM Customers
WHERE CustomerName LIKE 'a%' OR CustomerName LIKE 'b%';

Boshlanish

Ma'lum bir harf yoki ibora bilan boshlanuvchi yozuvlarni qaytarish uchun, harf yoki iboraning oxiriga % qo'shing.

Misol: La harfi bilan boshlanuvchi mijozlar:

SELECT * FROM Customers
WHERE CustomerName LIKE 'La%';

Tugash

Ma'lum bir harf yoki ibora bilan tugaydigan yozuvlarni qaytarish uchun, harf yoki iboraning boshiga % qo'shing.

Misol: a bilan tugaydigan mijozlar:

SELECT * FROM Customers
WHERE CustomerName LIKE '%a';

Ichida

Ma'lum bir harf yoki ibora ichida bo'lgan yozuvlarni qaytarish uchun, har ikki tomonida % qo'shing.

Misol: or iborasi bor mijozlar:

SELECT * FROM Customers
WHERE CustomerName LIKE '%or%';

Wildcardlarni Birlashtirish

Har qanday wildcard, masalan, % va _, boshqa wildcardlar bilan birgalikda ishlatilishi mumkin.

Misol: a bilan boshlanuvchi va kamida 3 belgi uzunlikka ega bo'lgan mijozlar:

SELECT * FROM Customers
WHERE CustomerName LIKE 'a__%';

Misol: Ikkinchi pozitsiyada r harfi bo'lgan mijozlar:

SELECT * FROM Customers
WHERE CustomerName LIKE '_r%';

Wildcardlarsiz

Agar hech qanday wildcard ko'rsatilmasa, ibora aniq mos kelishi kerak.

Misol: Ispaniyadan bo'lgan barcha mijozlar:

SELECT * FROM Customers
WHERE Country LIKE 'Spain';

Ushbu sahifada

Xato haqida xabar berish