Worked Examples · Example 9.15
Q.The following query selects details of all those employees whose name consists of exactly 5 letters and starts with any letter but has 'ANYA' after that.
Yanam CbseNCERTSubjective· 2mImportance★★★★★
31% · 29/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 →Example 9.15, on the real EMPLOYEE table (Table 9.8): the pattern '_ANYA' — one arbitrary character followed by the literal 'ANYA' — matches exactly two names, Sanya and Tanya.
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 |
The requirement is: exactly 5 letters, first letter can be anything, and the last four letters must be 'ANYA'. The pattern '_ANYA' does exactly this — _ matches exactly one character, and ANYA matches the literal suffix.
mysql> SELECT * FROM EMPLOYEE
-> WHERE Ename like '_ANYA';
Checking every real name: only Sanya and Tanya are 5 letters long and end in 'ANYA'. (Kritika is 7 letters and doesn't end in ANYA; none of the others do either.)
Output …
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.