Skip to content
Activities · Activity 9.12

Q.Using the table EMPLOYEE from CARSHOWROOM database, write SQL queries for the following:

a) Display employee name and the last 2 characters of his EmpId.
b) Display designation of employee and the position of character ‘e’ in designation, if present.
Uttar Pradesh UpmspTextbookSubjective· 4mImportance★★★★★est
25% · 24/95 Questions
🔒 Locked · start free trial →

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)

EmpIDEmpNameDesignation
E001RushilSalesman
E002SanjaySalesman
E003ZoharPeon
E004ArpitSalesman
E006SanjuctaReceptionist
E007MayankSalesman
E010RajkumarSalesman

(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

EmpNameLastTwoChars
Rushil01
Sanjay02
Zohar03
Arpit04
Sanjucta06
Mayank07
Rajkumar10

(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.