CS FundamentalsModerateHCLTech · Infosys placement pattern

Table Products(pid, pname, category, price, stock) rows: (1, 'Pen', 'Stationery', 10, 100), (2, 'Notebook', 'Stationery', 50, 0), (3, 'Laptop', 'Electronics', 50000, 5), (4, 'Mouse', 'Electronics', 500, NULL), (5, 'Chair', 'Furniture', 2000, 20), (6, 'Desk', 'Furniture', NULL, 3), (7, 'Pencil', 'Stationery', 5, 200). Which product names does this query return?

Table Products(pid, pname, category, price, stock) rows: (1, 'Pen', 'Stationery', 10, 100), (2, 'Notebook', 'Stationery', 50, 0), (3, 'Laptop', 'Electronics', 50000, 5), (4, 'Mouse', 'Electronics', 500, NULL), (5, 'Chair', 'Furniture', 2000, 20), (6, 'Desk', 'Furniture', NULL, 3), (7, 'Pencil', 'Stationery', 5, 200). Which product names does this query return?
SELECT pname FROM Products
WHERE pname LIKE '_e%';
  1. A. Pen, Desk, Chair
  2. B. Pen, Pencil, Desk
  3. C. Pen, Pencil
  4. D. Notebook, Desk

Correct answer: B. Pen, Pencil, Desk

The underscore matches exactly one character, so the SECOND letter of the name must be 'e': Pen (P-e-n), Pencil (P-e-n...) and Desk (D-e-s-k) qualify. Notebook's second letter is 'o', Laptop's is 'a', Chair's is 'h' and Mouse's is 'o'.

More DBMS and SQL questions

Exams that ask this topic