Worked Examples · Example 9.13
Q.The following query selects details of all those employees whose name starts with 'K'.
Tripura TbseTextbookSubjective· 2mImportance★★★★★
26% · 25/95 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →This is Example 9.13 from the OFFICE database's EMPLOYEE table (Table 9.8). The query uses LIKE 'K%' to find names starting with 'K'; only Kritika matches.
The real EMPLOYEE table (Table 9.8)
| EmpNo | Ename | Salary | Bonus | DeptId |
|---|---|---|---|---|
| 101 | Aaliya | 10000 | 234 | D02 |
| 102 | Kritika | 60000 | 123 | D01 |
| 103 | Shabbir | 45000 | 566 | D01 |
| 104 | Gurpreet | 19000 | 565 | D04 |
| 105 | Joseph | 34000 | 875 | D03 |
| 106 | Sanya | 48000 | 695 | D02 |
| 107 | Vergese | 15000 | NULL | D01 |
| 108 | Nachaobi | 29000 | NULL | D05 |
| 109 | Daribha | 42000 | NULL | D04 |
| 110 | Tanya | 50000 | 467 | D05 |
When you need to find data that matches a pattern rather than an exact value, SQL provides the LIKE operator together with wildcard characters:
%matches zero, one, or multiple characters._matches exactly one character.
Here we want employees whose name starts with 'K', so the pattern is 'K%':
mysql> SELECT * FROM EMPLOYEE
-> WHERE Ename like 'K%';
``` …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.