Programming languages

SQL

The standard declarative query language for relational databases: selecting, changing and defining data.

What it is

SQL grew out of IBM research in the 1970s on Edgar Codd's relational model. The first ANSI standard came in 1986, followed by ISO/IEC 9075. New editions still appear (SQL:2016, SQL:2023).

The language is declarative: you describe what data you need, and the database planner decides how to get it. The main command groups are DQL (SELECT), DML (INSERT, UPDATE, DELETE), DDL (CREATE, ALTER) and transaction control.

Every database (PostgreSQL, MySQL, SQLite, SQL Server, Oracle) has its own dialect with extensions, but the core is shared. Modern SQL supports window functions, CTEs, recursive queries and JSON.

Use it when

  • Structured data with relationships: users, orders, payments.
  • Analytics and reports: aggregations, grouping, window functions.
  • You need transactions and data integrity.
  • Several applications work with the same data.

Avoid it when

  • Loosely structured documents with a changing schema, where a document database fits better.
  • Complex processing logic that belongs in application code, not in hundreds of lines of SQL.

Key concepts

JOIN
Combines rows from several tables by a condition: INNER, LEFT, RIGHT, FULL.
GROUP BY and aggregates
Groups rows and computes COUNT, SUM, AVG. HAVING filters groups.
Index
A structure that speeds up lookups but slows down writes.
Transaction (ACID)
A group of operations either completes fully or not at all.
Window functions and CTE
OVER (...) computes over a window of rows, WITH gives named subqueries.

Example

Top 10 customers by revenue: JOIN, GROUP BY, HAVING.

Interview questions

  1. 1. How do INNER JOIN and LEFT JOIN differ?

    INNER JOIN returns only rows that match in both tables. LEFT JOIN returns all rows of the left table and fills the right side with NULL where there is no match.

  2. 2. WHERE or HAVING?

    WHERE filters rows before grouping, HAVING filters grouped results, for example by SUM or COUNT.

  3. 3. What is an index and when does it hurt?

    An index (usually a B-tree) speeds up lookups and sorting. But it takes space and slows INSERT / UPDATE, so unneeded indexes hurt.

  4. 4. What is a transaction and ACID?

    A transaction is an atomic group of operations. ACID means atomicity, consistency, isolation, durability. It prevents half-applied data after a failure.

Interview questions from the bank

Logos belong to their owners and are used for identification only. Icons: Simple Icons (CC0), Devicon (MIT).