Q.Using the table EMPLOYEE from CARSHOWROOM database, write SQL queries for the following:
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 question tests string functions in SQL — RIGHT() to extract trailing characters and INSTR() to find the position of a substring — applied to the real EMPLOYEE table (Table 9.12) of the CARSHOWROOM database.
The real EMPLOYEE table (Table 9.12)
| EmpID | EmpName | Designation |
|---|---|---|
| E001 | Rushil | Salesman |
| E002 | Sanjay | Salesman |
| E003 | Zohar | Peon |
| E004 | Arpit | Salesman |
| E006 | Sanjucta | Receptionist |
| E007 | Mayank | Salesman |
| E010 | Rajkumar | Salesman |
(a) Display employee name and the last 2 characters of his EmpId.
SELECT EmpName, RIGHT(EmpID, 2) AS LastTwoChars
FROM EMPLOYEE;
RIGHT(EmpID, 2) returns the rightmost 2 characters of each EmpID — e.g. RIGHT('E004', 2) gives '04'.
Output
| EmpName | LastTwoChars |
|---|---|
| Rushil | 01 |
| Sanjay | 02 |
| Zohar | 03 |
| Arpit | 04 |
| Sanjucta | 06 |
| Mayank | 07 |
| Rajkumar | 10 |
(b) Display designation of employee and the position of character 'e' in designation, if present.
SELECT Designation, INSTR(Designation, 'e') AS PositionOfE
FROM EMPLOYEE
WHERE INSTR(Designation, 'e') > 0;
INSTR(Designation, 'e') returns the 1-based index of the first 'e'. In MySQL, INSTR() is case-insensitive by default for non-binary strings (matching this same question's own short-answer note) — not that it matters here, since every real designation in this table already contains a lowercase 'e', so the WHERE filter excludes nothing.
"Salesman": S(1) a(2) l(3) e(4) — position 4."Peon": P(1) e(2) — position 2. …
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.