SQL is the standard language for managing relational databases. It allows you to create, modify, and query data efficiently. Essential knowledge for data engineering, analysis, and backend development.
SQL commands are grouped into distinct sublanguages based on their primary function within the database.
Defining the database structure (schema).
CREATE TABLE AS SELECT by directly selecting data from an existing table or query.Manipulating data within the database.
Focuses solely on retrieving data.
Data Control Language (DCL): Controlling access.
Transaction Control Language (TCL): Managing transactions (logical units of work).
Every column in a database table must have a defined data type. Operators allow you to perform calculations and comparisons on these data types.
+, -, *, /, % (modulo)=, !=, >, <, >=, <=|| (concatenation), LIKE, NOT LIKE (pattern matching)@ or :)AND, OR, NOT& (AND), | (OR), ^ (XOR), ~ (NOT)IN, BETWEEN, IS NULL, IS NOT NULL-- This is a comment | Multi-line: /* This is a multi-line comment */SQL follows general mathematical order of operations (parentheses first, then multiplication/division, then addition/subtraction, etc.).
ASC or descending DESC).GROUP BY is necessary when you want to apply aggregate functions to subsets of your data. For the entire dataset, not needed.
Conditional:
SubQueries:
Union combines the rows of two or more tables with similar structures (same number of columns and compatible data types). Removes duplicate rows by default (unless UNION ALL). Think of it as stacking tables on top of each other.
Join combines columns from two or more tables based on a related column between them. Link information from different tables. Determine which rows are included in the output based on matches in the join condition.
Window Functions:
Ranking data:
Watch the SQL 101 blueprint video on YouTube for a visual walkthrough.
Watch on YouTubeQ1. What does DDL stand for and give an example command?
Q2. What is the difference between UNION and UNION ALL?
Q3. Which join returns all rows from both tables even if there is no match?
Q4. What is the purpose of the GROUP BY clause?
Q5. What is the difference between RANK and DENSE_RANK window functions?