SQL (Structured Query Language)
SQL is the standard language for defining, querying and changing data held in relational databases, where data sits in tables of rows and columns. It is standardised as ISO/IEC 9075. Analysts use it to select, filter, join and aggregate tables.
What it is
SQL (Structured Query Language) is the standard language for asking questions of data stored in relational databases and for defining and changing that data. A relational database holds data in tables made of rows and columns, and links tables through shared columns. The ISO/IEC 9075 series defines the language in parts; one part sets the framework, another the core data structures and operations, and another the way applications call SQL from other programming languages.
SQL statements fall into three groups:
- Query statements read data. The SELECT statement is the main one.
- Data change statements add, alter or delete rows.
- Definition statements create or change the tables and columns themselves.
A query is built from clauses:
- SELECT names the columns to return.
- FROM names the table.
- JOIN links a second table through a shared column.
- WHERE filters rows before grouping.
- GROUP BY with a function such as SUM or COUNT summarises rows into groups.
- ORDER BY sorts the result.
Database systems add their own extensions, so the core statements are portable and the advanced ones need adapting.
Why it matters
Most financial data sits in databases: trades, positions, ledgers, client records. SQL is how an analyst reaches it without waiting for someone to build a report. A query is also a record of how a number was produced, so another person can read it, rerun it and check it.
Wrong SQL gives a plausible but wrong figure. A join on the wrong column, or a filter in the wrong place, changes the total without any error message.
Worked example
Illustrative numbers. A table trades holds five rows (trade_id, desk, notional): 1, A, 100; 2, A, 250; 3, B, 80; 4, B, 120; 5, B, 50. A second table desks gives each desk its region: A is North, B is South.
SELECT d.region, SUM(t.notional) AS total
FROM trades t
JOIN desks d ON d.desk = t.desk
WHERE t.notional >= 100
GROUP BY d.region
Step by step: the join attaches a region to each trade; the filter keeps trades 1, 2 and 4; the grouping adds them by region.
Result: North = 100 + 250 = 350; South = 120.
Trades 3 and 5 are dropped by the filter. If the filter is moved after the grouping, or removed, South becomes 80 + 120 + 50 = 250, which answers a different question.
How to read it
A result is read against the question and against a check: the row count before and after each join, and the total compared with a source report. A join that multiplies rows, because the linking column is not unique, inflates sums.
Assumptions
- The tables have documented linking columns and a clear meaning for each column, as in a data dictionary.
- The data is loaded and up to date; a query reads what is stored, not what happened.
- Missing values (nulls) are handled on purpose, because comparisons with null are neither true nor false.
Who uses it
- Data analysts extract, clean and summarise data for questions from the business.
- Banking data analysts query warehouse tables to explain differences between systems and reports.
- Business intelligence analysts write the queries that feed dashboards.
- Regulatory reporting analysts query source tables to trace the figures in a return back to the records.
- FP&A analysts pull actuals and drivers from the ledger and planning data.
Common confusions
- SQL is a language, not a database. Many database systems implement it with differences in the details.
- Joins on a non-unique column duplicate rows and inflate totals; the join type (inner or left) also decides whether unmatched rows disappear.
- WHERE filters rows before grouping; HAVING filters groups after it.
- Python and SQL are not alternatives. SQL retrieves and summarises data inside the database; Python adds modelling and automation.