SQL
SQL (Structured Query Language) is the standard language for working with relational databases.
Overview
SQL (Structured Query Language) is the standard language for working with relational databases. Originally developed at IBM in the 1970s, SQL allows you to store, retrieve, update, and analyze data using declarative statements - meaning you describe what you want, not how to get it. SQL has become the foundation of most modern data work, from basic data analysis to complex data pipelines.
Key Concepts
SQL operates primarily through statements that begin with commands like SELECT, INSERT, UPDATE, and DELETE. The most commonly used is SELECT for querying data. SQL also includes commands for defining and modifying database structures using CREATE, ALTER, and DROP.
DuckDB Examples
DuckDB implements most standard SQL syntax while adding some helpful extensions. Here's a basic query:
Copy code
SELECT city, COUNT(*) as num_customers
FROM customers
GROUP BY city
ORDER BY num_customers DESC;
DuckDB extends standard SQL with convenient shortcuts like SELECT * replacements:
Copy code
-- Standard SQL requires listing all columns except full_name
SELECT id, email, phone, address
FROM customers;
-- DuckDB allows excluding specific columns
SELECT * EXCLUDE (full_name)
FROM customers;
DuckDB also adds powerful extensions for working with semi-structured data:
Copy code
-- Query nested JSON data
SELECT json_extract_path(data, 'user', 'address', 'city') as city
FROM events;
-- Work with arrays
SELECT unnest(string_split(tags, ',')) as individual_tags
FROM posts;
Common Use Cases
Data analysts use SQL to explore datasets, create reports, and build dashboards. Data engineers use SQL to transform data, build data pipelines, and optimize database performance. SQL's ubiquity means it integrates well with visualization tools like Tableau, analysis notebooks like Jupyter, and modern data warehouses like Snowflake.
Best Practices
Writing clear, maintainable SQL involves consistent formatting, clear table aliases, appropriate comments, and breaking complex queries into manageable CTEs (Common Table Expressions). While SQL is fairly forgiving in terms of formatting, following consistent patterns makes queries easier to understand and modify.
Watch: Friendly SQL with DuckDB
Related terms
A SQL query is a structured request written in Structured Query Language (SQL) that allows you to retrieve, analyze, or manipulate data stored in a database.
SQL analytics →SQL analytics refers to using SQL queries to analyze data and derive insights, typically working with large datasets stored in databases or data warehouses.
relational database →A relational database is a structured collection of data organized into tables with rows and columns.
query →A query is a request made to a database to retrieve, modify, or analyze data.
relational object →A relational object is a fundamental concept in relational databases, representing a structured collection of data organized into rows and columns.
DuckDB →DuckDB is an embeddable SQL database management system designed for analytical workloads.

