Queries — SQL Technical Interview Questions & Answers
Queries
Queries
- A query is a SQL statement that asks for or changes data. The ones you must type without thinking: SELECT, INSERT, UPDATE, DELETE. Plus CREATE for structure. People also say ‘query’ only for SELECT — in a viva, say DML vs DDL if they split hairs.
- SELECT reads. INSERT adds a row. UPDATE changes a row. DELETE removes a row. Always practise SELECT with the same WHERE before UPDATE/DELETE.
- Read a query in this order in your head: FROM (which table) → WHERE (which rows) → SELECT (which columns). GROUP BY / HAVING / ORDER BY come after that story.
- Trap: SELECT * in every answer. Name columns. Trap: UPDATE without WHERE — whole table becomes 0 marks.
- On the example next to this theory: Queries: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
Technical Interview Tip: Name CRUD. Warn: no WHERE on UPDATE. Prefer listing columns.
Code Examples for Queries
Queries — sample query
-- Queries
CREATE TABLE demo (
id INTEGER PRIMARY KEY,
label TEXT NOT NULL,
qty INTEGER DEFAULT 0
);
INSERT INTO demo (id, label, qty) VALUES
(1, 'alpha', 2),
(2, 'beta', 5);
SELECT label, qty FROM demo WHERE qty >= 2 ORDER BY qty DESC;Queries: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
How to Explain Queries to an Interviewer
What are the four data queries?
SELECT, INSERT, UPDATE, DELETE
In what order do you read a SELECT?
FROM, then WHERE, then SELECT columns