SQL Cheat Sheet

Welcome to SQL Seeker's ultimate SQL Keyword and Cheat Sheet Reference!

Whether you're just starting with SQL or brushing up on advanced queries, this handy guide lists essential SQL keywords and functions to help you write better queries. From basic commands like SELECT to powerful aggregates like COUNT, each entry includes syntax, a brief description, and a practical example to get you going. Use this reference alongside our detailed lessons to master SQL, and explore our site-wide search for more learning resources.

SQL Keyword Reference Table

Keyword

Category

Syntax

Description

Example

SELECT

Queries

SELECT column1, column2 FROM table

Retrieves data from a table.

SELECT name, age FROM users;

FROM

Queries

FROM table

Specifies the table to query.

SELECT * FROM orders;

WHERE

Queries

WHERE condition

Filters rows based on a condition.

SELECT name FROM users WHERE age > 30;

INNER JOIN

Joins

INNER JOIN table ON condition

Joins tables, keeping matching rows.

SELECT users.name, orders.amount FROM users INNER JOIN orders ON users.id = orders.user_id;

LEFT JOIN

Joins

LEFT JOIN table ON condition

Joins tables, keeping all left table rows.

SELECT users.name, orders.amount FROM users LEFT JOIN orders ON users.id = orders.user_id;

GROUP BY

Aggregates

GROUP BY column

Groups rows by column for aggregation.

SELECT department, COUNT(*) FROM employees GROUP BY department;

HAVING

Aggregates

HAVING condition

Filters grouped results.

SELECT department, COUNT() FROM employees GROUP BY department HAVING COUNT() > 5;

ORDER BY

Queries

ORDER BY column ASC/DESC

Sorts results by column.

SELECT name FROM users ORDER BY age DESC;

LIMIT

Queries

LIMIT number

Restricts the number of rows returned.

SELECT * FROM products LIMIT 10;

COUNT

Aggregates

COUNT(column)

Counts non-null values in a column.

SELECT COUNT(*) FROM orders;

SUM

Aggregates

SUM(column)

Sums values in a column.

SELECT SUM(amount) FROM orders;

AVG

Aggregates

AVG(column)

Calculates average of a column.

SELECT AVG(price) FROM products;

MIN

Aggregates

MIN(column)

Finds the smallest value in a column.

SELECT MIN(price) FROM products;

MAX

Aggregates

MAX(column)

Finds the largest value in a column.

SELECT MAX(price) FROM products;

CONCAT

String Functions

CONCAT(string1, string2)

Concatenates strings.

SELECT CONCAT(first_name, ' ', last_name) AS full_name FROM users;

UPPER

String Functions

UPPER(string)

Converts string to uppercase.

SELECT UPPER(name) FROM products;

LOWER

String Functions

LOWER(string)

Converts string to lowercase.

SELECT LOWER(name) FROM products;

DATE

Date Functions

DATE(value)

Extracts date from a datetime.

SELECT DATE(order_date) FROM orders;

YEAR

Date Functions

YEAR(date)

Extracts year from a date.

SELECT YEAR(order_date) FROM orders;

LIKE

Queries

LIKE pattern

Matches patterns in strings.

SELECT name FROM users WHERE name LIKE '%son';