Which of the following query selects details of those employees whose name consists of exactly 4 letters and starts with letter 'p'?
Which of the following query selects details of those employees whose name consists of exactly 4 letters and starts with letter 'p'?
Solution
In SQL, the LIKE operator uses _ to match exactly one character and % to match any number of characters (including none). The pattern 'p___' is the letter p followed by three single-character wildcards, so it matches names of exactly 4 letters that start with p.
Option 2: '___p' matches 4-letter names that end with p, not start with it.
Option 3: 'p%' matches any name starting with p, of any length.
Option 4: '%p__' matches names with p as the third-last letter, of any length of 3 or more.
Remember: _ fixes the number of characters, while % leaves the length open.
Related questions:
2026: 26 May Shift 1
2025: 20 May Shift 1
2026: 13 May Shift 2
2026: 29 May Shift 2