Interview Q&A · SQL · 10 questions in this topic

SQL Fundamentals — SQL Interview Q&A

All SQL topics

The vocabulary every SQL interview opens with — what SQL and databases are, and how the language is organized. Part of SQL Fundamentals · 192 questions in the SQL bank.

What is SQL?

Answer

SQL (Structured Query Language) is the declarative standard language for storing, querying and managing data in relational databases. You describe what result you want (SELECT ... WHERE ... GROUP BY), and the database engine decides how to execute it via its query planner.

It is standardized (SQL:2023 is current) with portable core syntax plus vendor dialects — PostgreSQL, MySQL, SQL Server, SQLite and Oracle all extend the standard differently.

Example

Example.sqlsql
SELECT department, AVG(salary) AS avg_pay
FROM employees
WHERE age > 30
GROUP BY department
HAVING AVG(salary) > 60000;

💡 Say declarative first — describing what, not how — that single word frames the whole language.

Why use a database instead of a spreadsheet or flat files?

Answer

Databases enforce structure (types, constraints), handle concurrent writers safely (transactions, locking), answer ad-hoc questions over millions of rows in milliseconds (indexes, query planner), and guarantee durability (write-ahead logging, crash recovery). Spreadsheets and flat files offer none of these past trivial scale.

The interview shorthand: integrity, concurrency, query power and durability — pick any two to elaborate.

Key points

  1. 1Integrity — types and constraints reject bad data.
  2. 2Concurrency — many writers, consistent results.
  3. 3Scale — indexes and planners over huge data.
  4. 4Durability — committed data survives crashes.

What is a relational database? What are tables, rows and columns?

Answer

A relational database organizes data into tables (relations) of rows (tuples/records) and columns (attributes), with each column having a type and each row identified by a key. Tables relate through shared key values (foreign keys), and SQL queries combine, filter and aggregate across them.

Codd's relational model (1970) is the theory; the table picture is the practice.

Example

Example.sqlsql
-- employees(id, name, department, salary)
-- departments(dept_id, location, head)
SELECT e.name, d.location
FROM employees e JOIN departments d
  ON e.department = d.dept_id;

Recommended resourcesAffiliate links · may earn us a commission

Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits