Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Exact equality matches (WHERE username = 'amit') work when you know the complete, precise string. However, real-world user interfaces require partial searching: finding all customers whose last name starts with "Sha", looking up emails ending with "@gmail.com", or searching for products containing the word "Wireless". In SQL, basic pattern matching is accomplished using the LIKE operator and wildcard characters.
| Wildcard Symbol | Meaning | Example Pattern | Matches | Does NOT Match |
|---|---|---|---|---|
% (Percent) | Matches zero, one, or multiple characters. | 'A%' | 'A', 'Amit', 'Ananya' | 'Rohan' |
_ (Underscore) | Matches exactly one single character. | 'R_m' | 'Ram', 'Rom', 'R-m' | 'Rohan', 'Rm' |
ESCAPE)What if you need to search for an actual literal percent sign (%) or underscore (_) stored in the database (e.g., finding a discount code named 'SALE_50%')?
In MySQL, the backslash (\) serves as the default escape character:
LIKEHow does the MySQL query optimizer handle B-Tree indexes when evaluating LIKE queries?
LIKE '%word%' is too slow. Use MySQL's Full-Text Search (MATCH ... AGAINST) or external search engines like Elasticsearch!LIKEIn MySQL, whether LIKE is case-sensitive depends entirely on the collation of the column:
utf8mb4_0900_ai_ci), LIKE 'amit%' matches 'Amit', 'AMIT', and 'amit'.BINARY operator:WHERE email LIKE '%@gmail.com' on a 50-million-row table will bypass your index, scanning every row and pegging CPU utilization at 100%.NOT LIKE (e.g., WHERE email NOT LIKE '%@spam.com').LIKE expression?LIKE expression?LIKE patterns CAN utilize a standard B-Tree index to perform a fast index range scan?'PROMO_') in MySQL?LIKE '_r%' match?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Membership Filtering with IN Operator | Handling NULL Values (IS NULL) |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.