Knowledge base / SQL

SQL: commands and functions with examples

SQL commands and functions used in analysis: filtering, grouping, JOINs, window functions, dates and text, with notes on engine differences.

99 entries

The SQL entries describe the commands and functions that appear in typical analytical queries: filtering, grouping, JOINs, window functions, dates and text. The basics, such as SELECT, WHERE and GROUP BY, behave similarly in most databases. Date, text and JSON functions do not. The same operation in PostgreSQL, SQL Server, MySQL and SQLite often has a different name or different arguments.

For engine-specific functions, check which dialect an example targets. Before you run a query on a large table, test it on a few rows where you know the correct result. With JOINs and aggregations in particular, such a test quickly reveals duplicated rows or lost NULL values.

If you are starting out, work through “Query basics”, “Aggregations” and “JOINs and set operations” in that order. The articles below the grid show fuller examples that combine several of these elements.

Query basics 7

Aggregations 7

JOINs and set operations 11

Conditions and NULL 5

Window functions 9

Dates and time 14

Text 19

Numeric functions 10

Types, JSON and database objects 17

Kajo Rudziński

Newsletter KajoData

Let’s keep in touch.

I write about data analysis, learning and changing careers. My newsletter and the sign-up form are in Polish. If that works for you, I’d be glad to see you there.