0% found this document useful (0 votes)
5 views

SQL_Cheat_Sheet_Updated

This SQL cheat sheet provides essential commands for basic queries, joins, aggregations, subqueries, common table expressions (CTEs), and window functions. It outlines how to retrieve and manipulate data using various SQL techniques. Key functions include COUNT, SUM, AVG, and different types of joins such as INNER, LEFT, and FULL OUTER JOIN.

Uploaded by

bcampbell16
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

SQL_Cheat_Sheet_Updated

This SQL cheat sheet provides essential commands for basic queries, joins, aggregations, subqueries, common table expressions (CTEs), and window functions. It outlines how to retrieve and manipulate data using various SQL techniques. Key functions include COUNT, SUM, AVG, and different types of joins such as INNER, LEFT, and FULL OUTER JOIN.

Uploaded by

bcampbell16
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

SQL Cheat Sheet

Basic Queries
SELECT column_name FROM table_name WHERE condition - Retrieves specific data.

Joins
INNER JOIN - Returns only matching records from both tables.
LEFT JOIN - Returns all records from the left table and matched records from the right.
RIGHT JOIN - Returns all records from the right table and matched records from the left.
FULL OUTER JOIN - Returns all records when there is a match in either table.

Aggregations
COUNT(column) - Counts the number of rows.
SUM(column) - Sums up all values in a column.
AVG(column) - Returns the average value of a column.
MIN(column) - Returns the smallest value in a column.
MAX(column) - Returns the largest value in a column.

Subqueries
SELECT * FROM table1 WHERE column IN (SELECT column FROM table2 WHERE condition) - Retrieves
data using a nested query.

Common Table Expressions (CTEs)


WITH cte_name AS (SELECT column FROM table WHERE condition) SELECT * FROM cte_name - Defines
a temporary result set.

Window Functions
ROW_NUMBER() OVER (PARTITION BY column ORDER BY column) - Assigns a unique number to rows.
RANK() - Assigns a rank to rows within a partition.
DENSE_RANK() - Assigns a rank to rows without gaps.
LEAD() - Accesses data from the next row.
LAG() - Accesses data from the previous row.

You might also like