Posted in

SQL Cheatsheet – A Quick Guide for Beginners & Developers

sql cheatsheet

Content Table

1. Basics

SHOW DATABASES;
USE database_name;
SHOW TABLES;

2. Data Types

  • Numbers → INT, BIGINT, DECIMAL, FLOAT
  • Strings → CHAR, VARCHAR, TEXT
  • Date/Time → DATE, DATETIME, TIMESTAMP
  • Boolean → BOOLEAN

3. Database & Table

CREATE DATABASE db_name;
DROP DATABASE db_name;

CREATE TABLE users (
  id INT PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(100) NOT NULL,
  email VARCHAR(100) UNIQUE,
  age INT,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

ALTER TABLE users ADD phone VARCHAR(15);
ALTER TABLE users DROP COLUMN phone;
DROP TABLE users;

4. Insert / Update / Delete

INSERT INTO users (name, email, age)
VALUES ('Alice', 'alice@mail.com', 22);

UPDATE users SET age = 23 WHERE id = 1;

DELETE FROM users WHERE id = 1;

5. Select Queries

SELECT * FROM users;
SELECT name, age FROM users;
SELECT DISTINCT age FROM users;
SELECT name AS full_name FROM users;

6. WHERE Clause

SELECT * FROM users WHERE age > 18;

-- Operators: =, !=, <>, >, <, <=, >=
-- Logical: AND, OR, NOT
-- Range: BETWEEN ... AND ...
-- List: IN (...)
-- Pattern: LIKE, ILIKE

7. Sorting & Limiting

SELECT * FROM users ORDER BY age ASC;
SELECT * FROM users ORDER BY age DESC;
SELECT * FROM users LIMIT 5 OFFSET 10;

8. Aggregate Functions

SELECT COUNT(*), AVG(age), MIN(age), MAX(age), SUM(age) FROM users;

9. GROUP BY / HAVING

SELECT age, COUNT(*) FROM users GROUP BY age;
SELECT age, COUNT(*) FROM users GROUP BY age HAVING COUNT(*) > 1;

10. Joins

-- Inner Join
SELECT u.name, o.order_date
FROM users u
INNER JOIN orders o ON u.id = o.user_id;

-- Left Join
SELECT u.name, o.order_date
FROM users u
LEFT JOIN orders o ON u.id = o.user_id;

-- Right Join
SELECT u.name, o.order_date
FROM users u
RIGHT JOIN orders o ON u.id = o.user_id;

-- Full Join (Postgres, MySQL 8+)
SELECT u.name, o.order_date
FROM users u
FULL OUTER JOIN orders o ON u.id = o.user_id;

11. Subqueries

SELECT * FROM users
WHERE age > (SELECT AVG(age) FROM users);

12. Set Operations

SELECT name FROM users
UNION
SELECT name FROM customers;

SELECT name FROM users
UNION ALL
SELECT name FROM customers;

13. Constraints

  • PRIMARY KEY
  • FOREIGN KEY
  • UNIQUE
  • NOT NULL
  • DEFAULT

14. Indexes

CREATE INDEX idx_name ON users(name);
DROP INDEX idx_name ON users;

15. Views

CREATE VIEW adult_users AS
SELECT * FROM users WHERE age >= 18;

SELECT * FROM adult_users;
DROP VIEW adult_users;

16. Transactions

START TRANSACTION;
UPDATE users SET age = age+1 WHERE id=1;
DELETE FROM users WHERE id=2;
COMMIT;
ROLLBACK;

17. Privileges

GRANT ALL PRIVILEGES ON db_name.* TO 'user'@'localhost';
REVOKE ALL PRIVILEGES ON db_name.* FROM 'user'@'localhost';

Advanced SQL

18. Stored Procedures

DELIMITER //
CREATE PROCEDURE GetUsers()
BEGIN
  SELECT * FROM users;
END //
DELIMITER ;

CALL GetUsers();

19. Functions

CREATE FUNCTION UserCount()
RETURNS INT
DETERMINISTIC
RETURN (SELECT COUNT(*) FROM users);

20. Triggers

CREATE TRIGGER before_insert_user
BEFORE INSERT ON users
FOR EACH ROW
SET NEW.created_at = NOW();

21. Window Functions (MySQL 8+, PostgreSQL)

SELECT name, age,
       RANK() OVER (ORDER BY age DESC) AS rank,
       ROW_NUMBER() OVER (PARTITION BY age ORDER BY name) AS row_num
FROM users;

22. CTEs (Common Table Expressions)

WITH avg_age AS (
   SELECT AVG(age) AS avg FROM users
)
SELECT * FROM users WHERE age > (SELECT avg FROM avg_age);

23. Recursive CTEs

WITH RECURSIVE numbers AS (
  SELECT 1 AS n
  UNION ALL
  SELECT n+1 FROM numbers WHERE n < 10
)
SELECT * FROM numbers;

24. JSON Data

-- MySQL JSON Example
SELECT JSON_EXTRACT(details, '$.address') FROM users;
SELECT details->>'$.phone' FROM users;

25. Temporary Tables

CREATE TEMPORARY TABLE temp_users AS
SELECT * FROM users WHERE age > 20;

26. Backup & Restore

-- Export
mysqldump -u user -p db_name > backup.sql  

-- Import
mysql -u user -p db_name < backup.sql

All CheatSheets view

Checkout other Cheatsheets

  1. Python
  2. JavaScript
  3. HTML
  4. CSS
  5. React

Checkout My YouTube Channel

Read my other Blogs

  1. Top 5 Mistakes Beginners Make While Learning to Code (And How to Avoid Them)
  2. Best Programming Languages to Learn in 2025 (and Why)
  3. Before You Learn Web Development: The Advice No One Gave Me
  4. How to Start Coding in 2025: Beginner’s Roadmap
  5. Why Coding is Important: The Language of the Future
  6. Are Coding and Programming the Same? – The Complete Truth You Need to Know
  7. Will Coding Be Replaced by AI?
  8. C++ Programming: Everything You Need to Know

I’m Shaurya, a developer simplifying tech with tutorials, tools, and projects to help you learn, build, and grow in the world of coding.

124 thoughts on “SQL Cheatsheet – A Quick Guide for Beginners & Developers

  1. This blog is extremely helpful and well-structured. The SQL cheatsheet is clear, easy to understand, and covers all the essential concepts in a simple way. It has made revising SQL much faster and more convenient for me. I really appreciate the effort put into explaining the commands so clearly—this kind of resource is very valuable for learners and developers alike. Great work and thank you for sharing such useful content!

  2. I found this blog to be very informative and practical. The SQL cheatsheet is well organized and makes understanding core SQL concepts much easier. It’s a great reference for quick revision and daily use, especially for beginners. I truly appreciate the clarity and effort behind this content—it’s been genuinely helpful for my learning. Keep up the great work!

  3. This blog is really well written and easy to follow. The SQL cheatsheet explains important concepts in a simple and effective way, making it very useful for quick learning and revision. I found it extremely helpful while practicing SQL, and I appreciate the effort put into creating such a clear and practical resource. Thanks for sharing this valuable content!

  4. I really enjoyed reading this blog. The SQL cheatsheet is concise, well-organized, and very easy to understand. It helped me quickly revise important SQL concepts without confusion. I appreciate the clarity and effort behind this post—resources like this make learning much more effective. Great job and thank you for sharing!

  5. This blog turned out to be very helpful for me. The SQL cheatsheet is simple, clear, and covers the most important commands in an easy-to-understand way. It made revising SQL much quicker and more efficient. I truly appreciate the effort and quality of this content. Excellent work and thanks for sharing such a useful resource!

  6. The SQL cheatsheet provided in this blog is extremely useful and well organized. It presents important SQL commands and concepts in a simple and concise manner, making it easy to revise and apply them in practice. This cheatsheet has saved a lot of time while learning and working with databases. I truly appreciate the effort put into creating such a helpful and beginner-friendly resource.

  7. This SQL cheatsheet is very clear, practical, and easy to follow. It highlights all the essential SQL commands in a structured way, which makes learning and revision much more efficient. I found it especially helpful for quick reference while practicing queries. Great effort on creating such a useful and well-presented resource. Thank you for sharing!

  8. The SQL cheatsheet in this blog is extremely well explained and easy to understand. It breaks down complex SQL concepts into simple, manageable points, making it very helpful for quick revision. I found it to be a reliable reference while learning and practicing SQL. I really appreciate the clarity and effort behind this content—excellent work!

  9. This SQL cheatsheet is thoughtfully created and very user-friendly. The way the commands and concepts are organized makes it easy to understand and remember them. It has been genuinely helpful for my SQL practice and revision. I appreciate the effort and clarity put into this blog. Great resource for learners!

  10. I found the SQL cheatsheet in this blog to be extremely practical and well presented. It covers the most important SQL topics in a clear and straightforward manner, making it perfect for quick reference. This content has really helped me improve my understanding of SQL. I appreciate the effort behind creating such a useful and learner-friendly resource.

  11. This SQL cheatsheet is incredibly helpful and easy to follow. It organizes all the essential commands and concepts in a simple, clear way, making it perfect for quick revision or practice. I really appreciate the effort put into creating such a practical and informative resource—it’s been a great help for my learning!

  12. The SQL cheatsheet in this blog is very well structured and easy to understand. It makes learning and revising SQL concepts quick and convenient. I really appreciate how clearly everything is explained—this resource is truly helpful for both beginners and anyone looking for a quick reference.

  13. Wow, this SQL cheatsheet is a lifesaver! It’s not just a list of commands—it actually makes SQL feel simple and approachable. The way everything is broken down step by step really helped me connect the concepts and see how they work in real queries. I genuinely enjoyed going through it, and it’s going to be my go-to reference from now on.

  14. I really love how this SQL cheatsheet simplifies complex concepts into easy-to-grasp points. It’s not just helpful for revision but also for understanding how SQL works in practice. The clear examples and organized layout make it a fantastic resource—I feel much more confident working with databases thanks to this guide!

  15. Great guide! The way you’ve summarized SQL commands makes it so easy to understand and use. Really appreciate the effort.

  16. Having this guide makes learning SQL so much smoother. It organizes commands and concepts clearly, helping me understand how to write queries correctly and revise efficiently.

  17. Studying SQL has become much more efficient with this guide. It clearly explains commands and concepts, making it easier to practice queries and understand how everything works together.

  18. This resource has made learning SQL much more manageable. With clear explanations and organized commands, I can quickly revise, understand complex queries, and apply them confidently.

  19. Having all the SQL commands and concepts organized in one place has made studying so much easier. It’s helped me understand how different queries work and saved a lot of time when practicing.

  20. Learning SQL has become much simpler thanks to this guide. It breaks down complex commands into easy-to-understand sections, making it faster to grasp concepts and apply them in real queries.

  21. Before discovering this resource, learning SQL felt overwhelming, but having all the commands and concepts organized so clearly has made it much easier to follow. I can now revise quickly, practice effectively, and feel more confident writing queries.

  22. This guide has completely changed the way I approach SQL. With all the commands and concepts laid out clearly, I can quickly find what I need, understand how everything works together, and practice with confidence.

  23. This SQL cheatsheet has made a huge difference in how I learn and practice SQL. Instead of getting lost in lengthy tutorials or notes, I can quickly find the commands I need, understand their usage, and see how they fit together. It has made studying SQL much more organized and efficient.

  24. Before I saw this SQL cheatsheet, I used to spend a lot of time searching for commands online or flipping through long notes. Now, everything I need is in one place, organized logically, and easy to follow. It has completely changed the way I approach learning SQL and made practicing queries much more efficient and less stressful.

  25. This SQL cheatsheet has been a real game-changer. It organizes all the important commands and concepts in one place, so I can easily revise, practice, and understand how queries work without getting overwhelmed. It’s made learning SQL much more manageable and even enjoyable.

  26. This SQL cheatsheet is extremely practical. It helps me quickly revise commands and understand how to use them effectively in real-world queries.

  27. This SQL cheatsheet is a great learning aid. It breaks down complex SQL concepts into simple points, making it easier to understand and apply them.

  28. This SQL cheatsheet is super handy. It helps me quickly find and understand commands, making SQL practice and revision much smoother.

  29. This SQL cheatsheet makes studying SQL much easier. It clearly organizes commands and concepts, helping me learn and revise efficiently.

  30. This SQL cheatsheet is a great reference. It makes practicing queries and recalling important commands much faster and easier.

  31. This SQL cheatsheet really simplifies learning. It’s easy to follow and helps me quickly grasp key commands and concepts without getting confused.

  32. This SQL cheatsheet has been a tremendous help in my learning journey. Before, I used to get overwhelmed trying to remember all the commands and functions, but now I can quickly refer to it and understand how everything works together. It not only makes revising SQL faster but also helps me feel more confident when writing queries and solving database problems.

  33. This SQL cheatsheet is really helpful. It makes learning and revising commands quick, clear, and much easier to understand.

  34. This SQL cheatsheet is extremely useful. It turns a lot of complicated SQL concepts into easy-to-follow points, making practice and revision much faster and more effective.

  35. This SQL cheatsheet has made learning SQL so much more manageable. The clear layout and concise explanations help me quickly grasp concepts and apply them without getting lost in details.

  36. This SQL cheatsheet has been really helpful for me. It organizes commands and concepts so clearly that I can quickly refer to it while practicing, making learning SQL much more efficient and less confusing.

  37. This SQL cheatsheet is incredibly practical. It helped me quickly understand how different commands work together and made revising SQL much faster and less stressful.

  38. This SQL cheatsheet is a real lifesaver. It breaks down all the essential commands in a clear and simple way, making it much easier to understand and apply SQL in practice.

  39. Using this SQL cheatsheet has been a huge time-saver. It simplifies complex concepts and provides a clear guide to all the essential commands, making learning and revision much smoother and more effective.

  40. This SQL cheatsheet has made practicing SQL so much easier. I can quickly find the commands I need and understand how to use them, which has boosted my confidence and made learning much more efficient.

  41. I never realized learning SQL could be this straightforward until I used this cheatsheet. It organizes all the essential commands clearly, so I can quickly revise and apply them without getting overwhelmed. Truly a very helpful resource!

  42. This SQL cheatsheet has been a huge help. It breaks down complex commands into simple, understandable points, making it easy to learn and remember. It’s made working with databases much less intimidating and much more manageable.

  43. This SQL cheatsheet is a game-changer. It helped me grasp concepts I previously found confusing and made practicing queries much simpler. I can now revise SQL quickly and feel more confident applying it in real projects.

  44. This SQL cheatsheet has been incredibly helpful for me. I was struggling to remember all the commands, but now I can quickly find what I need and understand how everything works. It has made learning SQL much easier and less confusing. Truly a valuable resource!

  45. Having this SQL cheatsheet is like having a roadmap for databases. Instead of getting lost in syntax, I can quickly find the command I need and understand how it works. It turns practicing SQL from a chore into something much more manageable and even satisfying.

  46. Learning SQL can be overwhelming, but this cheatsheet turns it into a manageable, step-by-step guide. Instead of memorizing everything, I can just glance at it and see how queries are structured, how joins work, and how to use aggregate functions. It feels like having a mini SQL handbook right at your fingertips.

  47. This SQL cheatsheet is straightforward and easy to understand. It highlights key commands and concepts, making it an excellent tool for both learning and quick reference.

  48. This SQL cheatsheet is concise and practical, offering a clear overview of essential commands. It’s perfect for quick revision and helps make working with databases much easier.

  49. This SQL cheatsheet is well-organized and easy to navigate. It provides a quick way to review essential SQL commands and concepts, making it an excellent resource for learners and developers alike.

  50. This SQL cheatsheet is very handy for learning and reviewing SQL. It presents all the essential commands in a simple, organized way, making it easy to grasp and apply them effectively.

  51. This SQL cheatsheet is incredibly practical and user-friendly. I especially appreciate how it highlights key commands and functions without overwhelming you with unnecessary details. It’s been a real time-saver for quick learning and reference, and it has made practicing SQL much more enjoyable.

  52. This SQL cheatsheet is simple, clear, and extremely useful. It helps quickly understand and recall important SQL commands, making practice and revision much more efficient.

  53. This SQL cheatsheet makes learning SQL simple and efficient. The commands and concepts are clearly organized, allowing for quick reference and easy practice, which is perfect for both beginners and experienced users.

  54. This SQL cheatsheet is a fantastic resource for quickly revising key commands and concepts. Its clear structure and practical examples make understanding and applying SQL much easier.

  55. This SQL cheatsheet is extremely clear and easy to follow. It breaks down important SQL commands and concepts in a way that makes learning and revising much faster. The organized layout and practical examples make it a valuable resource for both beginners and anyone looking to strengthen their SQL skills.

  56. This SQL cheatsheet is concise, well-structured, and very practical. It covers all the essential commands and concepts in a way that’s easy to understand and remember. It’s a great reference for quick revision and helps make SQL much less intimidating for learners.

Leave a Reply

Your email address will not be published. Required fields are marked *

0
    0
    Your Cart
    Your cart is emptyReturn to Shop