Essential SQL Concepts You Must Know (With Examples)


Whether you're preparing for SQL interviews or building robust real-world applications, mastering these SQL fundamentals is non-negotiable.
This guide breaks down the core SQL concepts you need to know, with simple examples and real-life relevance.
1. Databases & Tables
A database stores structured data.
A table organizes data into rows (records) and columns (fields).
π Think of a table like an Excel sheet β each column has a specific data type, and each row is a data record.
2. SQL Syntax Basics
SELECT column1, column2
FROM table_name
WHERE condition;
SELECT
: Fetch dataFROM
: Specify the tableWHERE
: Apply filters and conditions
3. Data Types
INT
,FLOAT
,DECIMAL
β Numeric dataVARCHAR
,TEXT
β StringsDATE
,DATETIME
,TIME
β Date/TimeBOOLEAN
β True/FalseNULL
β Unknown or missing value
4. Filtering Data
SELECT * FROM users
WHERE age > 25 AND city = 'Mumbai';
π οΈ Use logical operators like:
AND
,OR
,NOT
IN
,LIKE
,BETWEEN
,IS NULL
5. Sorting & Limiting
SELECT * FROM orders
ORDER BY amount DESC
LIMIT 5;
Sort data using ORDER BY
and control the result count with LIMIT
.
6. Aggregate Functions
COUNT()
β Number of rowsSUM()
β Total sumAVG()
β AverageMAX()
/MIN()
β Highest/Lowest
SELECT department, AVG(salary)
FROM employees
GROUP BY department;
Used mostly with GROUP BY
.
7. Joins (Combining Tables)
SELECT e.name, d.name
FROM employees e
JOIN departments d ON e.dept_id = d.id;
INNER JOIN
β Matching records from both tablesLEFT JOIN
β All from left + matched from rightRIGHT JOIN
,FULL OUTER JOIN
β Other combinations
8. Subqueries
SELECT name
FROM users
WHERE id IN (SELECT user_id FROM orders);
Subqueries are queries inside another query.
9. Set Operations
UNION
β Combine unique resultsUNION ALL
β Includes duplicatesINTERSECT
,EXCEPT
β Set comparisons
10. Constraints
Constraints enforce data rules.
PRIMARY KEY
β Uniquely identifies a rowFOREIGN KEY
β References another tableUNIQUE
,NOT NULL
,DEFAULT
,CHECK
β Additional controls
11. Views
CREATE VIEW top_customers AS
SELECT name, SUM(amount) AS total
FROM orders
GROUP BY name;
Views are virtual tables created from queries β useful for reporting or hiding complex logic.
12. Indexes
CREATE INDEX idx_name ON employees(name);
Indexes boost query performance, especially on large datasets.
13. Transactions & ACID Properties
START TRANSACTION;
-- your SQL statements
COMMIT; -- or ROLLBACK;
Transactions group multiple steps into one unit.
β ACID stands for:
Atomicity β All or nothing
Consistency β Valid data only
Isolation β No interference
Durability β Changes persist
14. Window Functions
SELECT name, salary,
RANK() OVER (ORDER BY salary DESC) AS rank
FROM employees;
Window functions perform calculations across a set of rows without collapsing the result (unlike aggregates).
15. Normalization
Normalization = Breaking larger tables into smaller ones to eliminate redundancy and ensure data integrity.
Forms include:
1NF β Atomic columns
2NF β Remove partial dependencies
3NF β Remove transitive dependencies
Learning SQL isn't just about writing queriesβit's about thinking in data. These concepts form the foundation of every backend system, BI tool, and data-driven app.
π Bookmark this article for your daily SQL revision.
Keep practicing. Build queries. Break them. Learn by doing.
π Found this helpful? Follow DevDaily for more developer blogs every week!
β Written by Rishabh Mishra
Subscribe to my newsletter
Read articles from Rishabh Mishra directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Rishabh Mishra
Rishabh Mishra
Hey, Iβm Rishabh β a developer who writes code like poetry and breaks things just to rebuild them better. .NET Full Stack Dev | Razor, C#, MVC, SQL, Angular β my daily playground. I believe in βlearning out loudβ β so I write about dev struggles, breakthroughs, and the weird bugs that teach the best lessons. From building ERP apps to tinkering with UI/UX β I turn business logic into beautiful experiences. Self-growth > Comfort zone | Debugging is my meditation Letβs turn curiosity into code β one blog at a time.