Topic01 / 52
SQL Introduction
What & Why
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
1-- SQL is NOT case sensitive, but convention capitalizes keywords
2SELECT column1, column2
3FROM table_name
4WHERE condition
5ORDER BY column1 ASC
6LIMIT 10;
7
8-- Comments
9-- Single line comment
10/* Multi-line
11 comment */Real-World Example
Querying a product catalog database:
example.ts
sql
1-- Get top 10 bestselling electronics under ₹20,000
2SELECT
3 product_name,
4 category,
5 price,
6 units_sold,
7 (price * units_sold) AS total_revenue
8FROM products
9WHERE
10 category = 'Electronics'
11 AND price < 20000
12 AND is_active = TRUE
13ORDER BY units_sold DESC
14LIMIT 10;Pitfalls & Interview Tips
- ⚠️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.