Topic 1 of 52
Introduction
Overview
SQL (Structured Query Language) is the universal language for managing relational databases. It is used to store, retrieve, update, and delete data — and knowledge of SQL is required for virtually every software engineering role.
Syntax
sql
-- SQL is NOT case sensitive, but convention capitalizes keywords
SELECT column1, column2
FROM table_name
WHERE condition
ORDER BY column1 ASC
LIMIT 10;
-- Comments
-- Single line comment
/* Multi-line
comment */Common Pitfalls
- SQL is declarative — you describe WHAT you want, not HOW to get it. The database optimizer decides the execution plan.
- NULL is not a value — it means 'unknown'. NULL = NULL is false. Use IS NULL / IS NOT NULL.
- Interview tip: The order of SQL clauses matters: SELECT → FROM → WHERE → GROUP BY → HAVING → ORDER BY → LIMIT.
Real-World Example
Querying a product catalog database:
example
sql
-- Get top 10 bestselling electronics under ₹20,000
SELECT
product_name,
category,
price,
units_sold,
(price * units_sold) AS total_revenue
FROM products
WHERE
category = 'Electronics'
AND price < 20000
AND is_active = TRUE
ORDER BY units_sold DESC
LIMIT 10;