LEFT()() — SQL Technical Interview Questions & Answers

LEFT()()

LEFT()()

  • LEFT() first n characters. You use it in SELECT (and sometimes WHERE/UPDATE). It does not change stored data unless you UPDATE … SET col = LEFT(col).
  • Board: SELECT LEFT(name, 1) FROM students; Run it. Say the result out loud. If the column is NULL, the result is often NULL — wrap with IFNULL if you need a blank instead.
  • String indexes in MySQL start at 1, not 0 (SUBSTR, INSTR, LEFT). Not the left table of a JOIN.
  • Interview: name LEFT, one argument list, one example on the students table. Don’t recite every string function.
  • On the example next to this theory: LEFT()() — jOIN combines rows using a match condition between tables.

Technical Interview Tip: Say what LEFT returns, then SELECT LEFT(name, 1) FROM students;

Code Examples for LEFT()()

LEFT()() — sample query

CREATE TABLE customers (id INTEGER PRIMARY KEY, name TEXT);
CREATE TABLE orders (id INTEGER PRIMARY KEY, customer_id INTEGER, total INTEGER);
INSERT INTO customers VALUES (1, 'Asha'), (2, 'Ravi');
INSERT INTO orders VALUES (10, 1, 500), (11, 1, 200);
SELECT c.name, o.total
FROM customers c
JOIN orders o ON o.customer_id = c.id;

LEFT()() — jOIN combines rows using a match condition between tables.

How to Explain LEFT()() to an Interviewer

What does LEFT do?

first n characters SELECT LEFT(name, 1) FROM students;

Does it UPDATE the table?

No, unless you write UPDATE SELECT only prints