SQL Mind Map: Essential Concepts and Syntax

Mastering SQL starts with knowing the structure. Here’s a clear, organized breakdown of core SQL topics with examples to help you build and query databases confidently.


SELECT

Used to retrieve data from one or more columns in a table.

SELECT column1, column2 FROM table;
SELECT * FROM users;

GROUP BY

Group data based on a column and apply aggregation functions.

SELECT department, COUNT(*) FROM employees GROUP BY department;
HAVING COUNT(*) > 5;

ORDER BY

Sort data based on one or more columns.

SELECT name, age FROM students ORDER BY age ASC;
ORDER BY salary DESC;

JOINS

Combine rows from two or more tables based on related columns.

  • INNER JOIN – Only matching rows
SELECT * FROM orders INNER JOIN customers ON orders.customer_id = customers.id;
  • LEFT JOIN – All rows from the left table, matched from the right
sqlCopyEditSELECT * FROM customers LEFT JOIN orders ON customers.id = orders.customer_id;
  • RIGHT JOIN – All rows from the right table, matched from the left
sqlCopyEditSELECT * FROM orders RIGHT JOIN customers ON orders.customer_id = customers.id;
  • FULL JOIN – All rows from both tables
sqlCopyEditSELECT * FROM table1 FULL JOIN table2 ON table1.id = table2.id;

FUNCTIONS

Perform calculations or summaries on data.

SELECT AVG(salary) FROM employees;
SELECT SUM(price) FROM orders;
SELECT COUNT(*) FROM products;
SELECT MIN(age) FROM users;
SELECT MAX(score) FROM results;

WHERE

Filter data based on specified conditions.

SELECT * FROM users WHERE age > 30;

Operators and Clauses:

  • LIKE
WHERE name LIKE 'A%';
  • IN
WHERE department IN ('HR', 'IT');
  • BETWEEN
WHERE salary BETWEEN 3000 AND 6000;
  • ANY
WHERE salary > ANY (SELECT salary FROM employees);
  • EXISTS
WHERE EXISTS (SELECT * FROM orders WHERE orders.user_id = users.id);
  • ALL
WHERE salary > ALL (SELECT salary FROM employees WHERE department = 'IT');
  • AND, OR, NOT
WHERE age > 25 AND status = 'active';
  • Comparison
=, >, <, >=, <=, <>

Amr Abdelkarem

About me

No Comments

Leave a Comment