The SQL Pro Cheatsheet 2025 provides essential SQL commands and concepts for students, interns, and job-ready developers. It covers basic syntax, filtering, aggregate functions, joins, subqueries, window functions, data types, table operations, and more. Additionally, it includes advanced topics like transactions, CTEs, and JSON functions to enhance SQL proficiency.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0 ratings0% found this document useful (0 votes)
4 views
SQL Pro Cheatsheet
The SQL Pro Cheatsheet 2025 provides essential SQL commands and concepts for students, interns, and job-ready developers. It covers basic syntax, filtering, aggregate functions, joins, subqueries, window functions, data types, table operations, and more. Additionally, it includes advanced topics like transactions, CTEs, and JSON functions to enhance SQL proficiency.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 6
SQL PRO
2025 Cheatsheet
Students, Interns & Job-Ready Devs
By- @helloworld_avaniSQL Pro Cheatsheet 2025
Basic SQL Syntax
Select from a table
SELECT column1, column2 FROM table_name;
(@ Filter rows
SELECT * FROM table WHERE condition;
(@ Sort results
SELECT * FROM table ORDER BY column ASC/DESC;
Remove duplicates
SELECT DISTINCT column FROM table;
Filtering & Conditions
(ESELECT * FROM employees WHERE salary > 50800 AND department = ‘HR';
SELECT * FROM users WHERE name LIKE 'A%';
MESELECT * FROM users WHERE age BETWEEN 18 AND 25;
(@BSELECT * FROM customers WHERE country IN (‘India’, ‘USA‘);
Aggregate Functions
GESELECT COUNT(*) FROM orders;
(ESELECT SUM(amount) FROM sales;
(ESELECT AVG(salary) FROM employees;
(EISELECT MIN(price), MAX(price) FROM products;
By- @helloworld_avanGROUP BY & HAVING
[ESELECT department, COUNT(*) FROM employees GROUP BY department;
MESELECT department, COUNT(*) FROM employees GROUP BY department
HAVING COUNT(*) > 5;
SQL Joins
JOIN TYPE Description
INNER Matching rows in both tables
LEFT All from left + matched right
RIGHT All from right + matched left
FULL All from both, matched & unmatched
MMISELECT * FROM orders o JOIN customers c ON o.customer_id = c.id;
Subqueries & Aliases
GESELECT name FROM employees WHERE salary > (SELECT AVG(salary) FROM
employees) ;
IESELECT name AS EmployeeName FROM users;
CASE Statement
SELECT name,
CASE
WHEN score >= 98 THEN ‘A’
WHEN score >= 80 THEN 'B’
ELSE 'C’
END AS grade
FROM students;
By- @helloworld_avaniWindow Functions
WESELECT name, salary, RANK() OVER (ORDER BY salary DESC) AS rank FROM
employees;
WBESELECT *, ROW_NUMBER() OVER (PARTITION BY department ORDER BY
salary DESC) FROM employees;
String & Date Functions
String Functions:
I UPPER(name)
HE LOWER (name)
ELENGTH(name)
WESUBSTRING(name, 1, 3)
Date Functions:
IM CURRENT_DATE
Wnow()
IM DATE_ADD(order_date, INTERVAL 7 DAY)
IE DATEDIFF(end_date, start_date)
WBEXTRACT(YEAR FROM birth_date)
Data Types (For Table Creation)
IBINT, FLOAT, VARCHAR(255), TEXT, DATE, BOOLEAN
IMICREATE TABLE users (id INT, name VARCHAR(18@), is_active BOOLEAN);
Table Operations (DDL)
WECREATE TABLE employees (id INT, name TEXT);
WBALTER TABLE employees ADD COLUMN salary INT;
IMDROP TABLE employees;
GBALTER TABLE employees RENAME TO staff;
By- @helloworld_avaniInsert, Update, Delete (DML)
IBINSERT INTO users (name, age) VALUES (‘Avani', 25);
MBuPDATE users SET age = 26 WHERE name = ‘Avani’;
MMEDELETE FROM users WHERE age < 20;
Constraints
(MPPRIMARY KEY, FOREIGN KEY, UNIQUE, NOT NULL, DEFAULT, CHECK
(EICREATE TABLE orders (id INT PRIMARY KEY, amount FLOAT CHECK (amount
> @));
Indexes & Optimization
WICREATE INDEX idx_name ON employees(name) ;
MMDROP INDEX idx_name;
IBEXPLAIN SELECT * FROM orders WHERE customer_id = 5;
Views
(ECREATE VIEW active_users AS SELECT * FROM users WHERE is_active =
TRUE;
(MISELECT * FROM active_users;
Stored Procedures & Functions
CREATE PROCEDURE GetTotalorders()
BEGIN
SELECT COUNT(*) FROM orders;
END;
By- @helloworld_avaniTransactions
W@secin;
WISAVEPOINT beforeUpdate;
i commit;
GEROLLBACK TO beforeUpdate;
CTE (Common Table Expressions)
WITH high-earners AS (
SELECT name, salary FROM employees WHERE salary > 100000
)
SELECT * FROM high_earners;
Set Operators: UNION / INTERSECT / EXCEPT
(BESELECT name FROM table1 UNION SELECT name FROM table2;
SELECT name FROM tablel INTERSECT SELECT name FROM table2;
IMESELECT name FROM table1 EXCEPT SELECT name FROM table2;
JSON & ARRAY Functions (Modern SQL)
SELECT JSON_EXTRACT(data, ‘$.name') FROM users;
MISELECT ARRAY_AGG(name) FROM employees;
Comment ‘SQL for
PDF version of this post
By- @helloworld_avani