Free tutorials & notes in Hindi & English · Clean code examples 🧰 Free PDF & Image Tools →
MySQL + SQL · Lesson 123

MySQL Cheat Sheet

In this lesson: Quick MySQL reference — DDL, DML, joins, functions, constraints, users and backup commands. Bookmark and revise fast.

Quick reference

This is a MySQL cheat sheet — the commands you use every day, in one place. Keep it handy while practising. Once these core patterns feel familiar, most real queries are just variations of them.

💡 Learn the shapes: SELECT ... FROM ... WHERE ...; INSERT/UPDATE/DELETE; JOIN; GROUP BY.

Databases and tables

SHOW DATABASES;
CREATE DATABASE shop;
USE shop;
SHOW TABLES;
CREATE TABLE items (id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(50), price INT);
DESCRIBE items;
ALTER TABLE items ADD stock INT;
DROP TABLE items;

Insert, update, delete

INSERT INTO items (name, price) VALUES ('Pen', 10);
INSERT INTO items (name, price) VALUES ('Pen', 10), ('Book', 50);  -- many rows
UPDATE items SET price = 12 WHERE id = 1;
DELETE FROM items WHERE id = 1;

Always add a WHERE to UPDATE and DELETE, or every row is affected.

Selecting and filtering

SELECT * FROM items;
SELECT name, price FROM items;
SELECT * FROM items WHERE price > 20;
SELECT * FROM items WHERE name LIKE 'P%';
SELECT * FROM items WHERE price BETWEEN 10 AND 50;
SELECT DISTINCT name FROM items;
SELECT * FROM items ORDER BY price DESC LIMIT 5;

Joins

-- inner join (only matches)
SELECT o.id, c.name
FROM orders o JOIN customers c ON o.customer_id = c.id;

-- left join (all left rows, matched or not)
SELECT c.name, o.id
FROM customers c LEFT JOIN orders o ON o.customer_id = c.id;

Aggregates and grouping

SELECT COUNT(*) FROM items;
SELECT AVG(price), MAX(price), MIN(price), SUM(price) FROM items;
SELECT name, COUNT(*) FROM items GROUP BY name;
SELECT name, COUNT(*) FROM items GROUP BY name HAVING COUNT(*) > 1;

Use WHERE to filter rows, HAVING to filter groups after GROUP BY.

Handy functions

SELECT NOW(), CURDATE();
SELECT UPPER(name), LOWER(name), LENGTH(name) FROM items;
SELECT ROUND(price, 2), CEIL(price), FLOOR(price) FROM items;
SELECT IFNULL(stock, 0) FROM items;
SELECT CONCAT(name, ' - ', price) FROM items;

Summary

  • Databases/tables: CREATE, USE, SHOW, DESCRIBE, ALTER, DROP.
  • CRUD: INSERT, SELECT, UPDATE, DELETE (always WHERE for change).
  • Filter with WHERE, LIKE, BETWEEN; sort with ORDER BY; cap with LIMIT.
  • Join with JOIN ... ON; use LEFT JOIN to keep unmatched rows.
  • Summarise with COUNT/SUM/AVG and GROUP BY / HAVING.

Next, practise these in SQL queries practice, or go deeper with 50 MySQL queries.

Frequently Asked Questions

What are the most-used MySQL commands?
The everyday commands are CREATE DATABASE/TABLE, USE, INSERT, SELECT, UPDATE, DELETE, plus WHERE, ORDER BY, GROUP BY, JOIN and aggregate functions like COUNT and SUM. Together they cover almost all daily database work.
How do I quickly recall MySQL syntax?
Keep a cheat sheet of the core patterns: SELECT columns FROM table WHERE condition, INSERT INTO table VALUES, UPDATE table SET ... WHERE, and DELETE FROM table WHERE. Once these shapes are familiar, most queries are variations of them.
What is the basic SELECT syntax in MySQL?
SELECT columns FROM table WHERE condition ORDER BY column LIMIT n;. You choose the columns, the table, an optional filter, an optional sort, and an optional row limit. Use * for all columns.
How do I join two tables in MySQL?
Use JOIN with an ON condition: SELECT ... FROM a JOIN b ON a.id = b.a_id;. INNER JOIN keeps only matching rows, while LEFT JOIN keeps all rows from the left table even without a match.
What are common MySQL aggregate functions?
COUNT, SUM, AVG, MIN and MAX are the main ones, usually with GROUP BY to summarise per group. For example, SELECT class, AVG(marks) FROM students GROUP BY class; gives the average per class.
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 Live Code Editor

This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.
Next topicMySQL Interview Questions Your progress: 123 / 151 (81%) · Lesson 124 / 151 Continue →

How was this lesson?

Your feedback helps us make the content better.

Write a review or suggestion (optional)

After approval, your name and city may appear publicly with your review. Please do not write your email or phone number.

▶ CodingEasily on YouTube

Learn with video lessons in easy Hindi

Featured video: RDBMS Part 3 – Class XI Commerce IT

▶ Subscribe – it’s free