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

SQL-Cheat-Sheet-PDF

This SQL cheat sheet provides essential commands for querying, filtering, and aggregating data in SQL, including examples for SELECT, WHERE, JOINs, and aggregate functions. It also covers operators like AND, OR, and IN, as well as transaction commands such as BEGIN TRANSACTION and COMMIT. The document serves as a quick reference for SQL syntax and operations.

Uploaded by

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

SQL-Cheat-Sheet-PDF

This SQL cheat sheet provides essential commands for querying, filtering, and aggregating data in SQL, including examples for SELECT, WHERE, JOINs, and aggregate functions. It also covers operators like AND, OR, and IN, as well as transaction commands such as BEGIN TRANSACTION and COMMIT. The document serves as a quick reference for SQL syntax and operations.

Uploaded by

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

SQL Cheat Sheet

Querying Data in SQL Filtering Data in SQL SQL Operator

SELECT WHERE AND

Retrieve Data From One Or More Tables Filter Rows Based On Specified Conditions Combines Multiple Conditions In A WHERE
Clause

SELECT * FROM employees;SELECT * FROM employees WHERE


department = 'IT';SELECT * FROM employees WHERE department = 'IT' AND salary >
60000;

DISTINCT LIKE OR

Select Unique Values From A Column Match A Pattern In A Column Specifies Multiple Conditions Where Any One
Of Them Should Be True

SELECT DISTINCT department FROMSELECT * FROM employees WHERE


employees;first_name LIKE 'J%';SELECT * FROM employees WHERE
department = 'HR' OR department = 'Finance';

WHERE IN NOT

Filter Rows Based On Specified Conditions Match Any Value In A List Negates A Condition

SELECT * FROM employees WHERE SELECT * FROM employees WHERE SELECT * FROM employees WHERE NOT
salary > 55000.00; department IN ('HR', 'Finance'); department = 'IT';

LIMIT BETWEEN ORDER BY

Limit The Number Of Rows Returned In The Match Values Within A Specified Range Sorts the Result Set in Ascending or
Result Set Descending Order

SELECT * FROM employees WHERE


SELECT * FROM employees LIMIT 3;salary BETWEEN 50000 AND 60000;SELECT * FROM employees ORDER BY
salary DESC;

FETCH IS NULL GROUP BY

Retrieve A Specified Number Of Rows From Match NULL Values Groups Rows that have the Same Values into
The Result Set Summary Rows

SELECT * FROM employees WHERE


SELECT * FROM employees FETCH FIRSTdepartment IS NULL;SELECT department, COUNT(*) AS
3 ROWS ONLY;employee_count FROM employees GROUP
BY department;

Aggregation Data in SQL Joins in SQL Indexes & Transactions in SQL

COUNT INNER JOIN CREATE INDEX

Count The Number Of Rows In A Result Set Retrieves Records That Have Matching Create an Index on a Table
Values in Both Tables

SELECT COUNT(*) FROM employees; CREATE INDEX idx_department ON


employees (department);
SELECT * FROM employees INNER JOIN
departments ON
employees.department_id = departments.department_id;

SUM LEFT JOIN DROP INDEX

Calculate The Sum Of Values In A Column Retrieves All Records from the Left Table and Remove an Index
the Matched Records from the Right Table

SELECT SUM(salary) FROM employees; DROP INDEX IF EXISTS


idx_department;
SELECT * FROM employees LEFT JOIN
departments ON
employees.department_id = departments.department_id;

AVG RIGHT JOIN BEGIN TRANSACTION

Calculate The Average Value Of A Column Retrieves All Records from the Right Table Start a New Transaction
and the Matched Records from the Left Table

SELECT AVG(salary) FROM employees;BEGIN TRANSACTION;


SELECT * FROM employees RIGHT JOIN departments ON
employees.department_id =
departments.department_id;

MIN FULL OUTER JOIN COMMIT

Find the Minimum Value in a Column Retrieves All Records When There Is a Match Save Changes Made During the Current
in Either the Left or Right Table Transaction

SELECT MIN(salary) FROM employees;


SELECT * FROM employees FULL OUTER COMMIT;
JOIN departments ON
employees.department_id = departments.department_id;

MAX CROSS JOIN ROLLBACK

Find the Maximum Value in a Column Retrieves the Cartesian Product of the Two Undo Changes Made During the Current
Tables Transaction

SELECT MAX(salary) FROM employees;


SELECT * FROM employees CROSS JOIN ROLLBACK;
departments;

To Learn More Commands, You can read this article here.

You might also like