Reading/Querying Data in SQL
Explore this section to get the cheat sheet on how to use select, distinct and other querying data in SQL.
9. SELECT: Retrieve Data From One Or More Tables
SELECT * FROM employees;
This query will retrieve all columns from the employees table.
10. DISTINCT: Select Unique Values From A Column
SELECT DISTINCT department FROM employees;
This query will return unique department names from the employees table.
11. WHERE: Filter Rows Based On Specified Conditions
SELECT * FROM employees WHERE salary > 55000.00;
This query will return employees whose salary is greater than 55000.00.
12. LIMIT: Limit The Number Of Rows Returned In The Result Set
SELECT * FROM employees LIMIT 3;
This query will limit the result set to the first 3 rows.
13. OFFSET: Skip A Specified Number Of Rows Before Returning The Result Set
SELECT * FROM employees OFFSET 2;
This query will skip the first 2 rows and return the rest.
14. FETCH: Retrieve A Specified Number Of Rows From The Result Set
SELECT * FROM employees FETCH FIRST 3 ROWS ONLY;
This query will fetch the first 3 rows from the result set.
15. CASE: Perform Conditional Logic In A Query
SELECT
first_name,
last_name,
CASE
WHEN salary > 55000 THEN 'High'
WHEN salary > 50000 THEN 'Medium'
ELSE 'Low'
END AS salary_category
FROM employees;
This query will categorize employees based on their salary into ‘High’, ‘Medium’, or ‘Low’.
SQL Cheat Sheet
In this article, we will explore the ultimate SQL cheat sheet with the PDF, covering a wide range of SQL commands, Joins in SQL, CRUD Operations, SQL Trigger, SQL Transactions, and advanced topics to help master SQL effectively.
SQL (Structured Query Language) is a Query language used for managing and manipulating relational databases databases. It allows users to interact with databases. SQL allows users to perform various tasks such as querying data, updating data, inserting new records, deleting records, creating and modifying database schemas, and managing permissions.
Table of Content
- Create a Database in SQL
- Creating Data in SQL
- Reading/Querying Data in SQL
- Updating/Manipulating Data in SQL
- Deleting Data in SQL
- Filtering Data in SQL
- SQL Operator
- Aggregation Data in SQL
- Constraints in SQL
- Joins in SQL
- SQL Functions
- Subqueries in SQL
- Views in SQL
- Indexes in SQL
- Transactions in SQL
- Advanced Mixed Data in SQL
- SQL Cheat Sheet PDF