Product area

SQL the Databricks Way

The SQL fundamentals that actually matter on Databricks: Spark SQL, differences from Postgres, types, functions, and the patterns that keep showing up in exams.

Concepts

8 in this area
  1. 1Spark SQL, the dialectSpark SQL is the dialect you write everywhere on Databricks: in the SQL editor, inside a notebook cell, behind spark.sql(...) in PySpark, and inside a pipeline. It looks close enough to Postgres or MySQL that a query someone learned on psql will often just…
  2. 2Types and castingSpark SQL's type system covers the usual numeric, string, and temporal types, plus complex types (ARRAY, MAP, STRUCT) and VARIANT for semi-structured values (see semi structured data). Types matter more here than in a row-store: Delta stores data…
  3. 3Joins and set operationsJoins combine rows from two table references on a matching condition; set operators combine the results of two queries with the same shape. Spark SQL's SQL-level syntax reads like any relational database, but the plan it compiles to is distributed - matching…
  4. 4Window functionsA window function computes a value per row using a set of "peer" rows - defined by PARTITION BY and ORDER BY - without collapsing them into one row the way GROUP BY does. Ranking a row within its group, comparing it to the previous row, or running a…
  5. 5MERGE, UPDATE, DELETE on DeltaMERGE INTO, UPDATE, DELETE, and INSERT OVERWRITE are the statements that change data already sitting in a Delta table instead of just appending to it. They read like ordinary DML from any relational database, but Delta has no in-place row storage: every one…
  6. 6AI functions in SQLAI functions are built-in SQL functions, all named ai, that apply a model to a column. They run from the SQL editor, from notebooks, from Lakeflow pipelines and from jobs, and they need no endpoint of your own: the query runs on the compute you submit it…
  7. 7Pipe syntax for queriesAny query on Databricks can be followed by a chain of pipe operators, each separated by the token |> and each consuming the result of the one before it. A pipeline normally starts with FROM main.silver.orders or TABLE main.silver.orders, but any query can…
  8. 8SQL scripting and stored proceduresSQL scripting is the procedural half of Databricks SQL. Everything lives inside a compound statement: a BEGIN ... END block that first declares local variables, conditions, cursors and error handlers, then runs a sequence of queries, DML, DDL, GRANT, loops…

Also covered here

2 filed under another area

Resources