Essential SQL Concepts You Must Know (With Examples)

Rishabh MishraRishabh Mishra
3 min read

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 data

  • FROM: Specify the table

  • WHERE: Apply filters and conditions


3. Data Types

  • INT, FLOAT, DECIMAL β€” Numeric data

  • VARCHAR, TEXT β€” Strings

  • DATE, DATETIME, TIME β€” Date/Time

  • BOOLEAN β€” True/False

  • NULL β€” 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 rows

  • SUM() β€” Total sum

  • AVG() β€” Average

  • MAX() / 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 tables

  • LEFT JOIN β€” All from left + matched from right

  • RIGHT 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 results

  • UNION ALL β€” Includes duplicates

  • INTERSECT, EXCEPT β€” Set comparisons


10. Constraints

Constraints enforce data rules.

  • PRIMARY KEY β€” Uniquely identifies a row

  • FOREIGN KEY β€” References another table

  • UNIQUE, 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

0
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.