Score 80%+ in the Exam & Win Certificate + Gifts!
- ✅ Full course 100% Free
- 🎓 Score 80%+ in Final Exam = Certificate
- 📝 50 Questions
- 🎁 Cheat Sheet + Gifts + Much More
What is SQL? SQL (Structured Query Language) is the standard language for storing, retrieving, updating and deleting data in relational databases such as MySQL, PostgreSQL, SQL Server and Oracle. This free guide gives you runnable examples, a live in-browser sandbox, the top 10 interview questions with answers, and a 50-question certificate exam. Last updated:
🧭 Brand New to SQL? Just understand these 4 core concepts!
SQL is not difficult programming. Imagine having an Excel Sheet open and typing instructions telling it exactly what to do:
SELECT (what to view) + FROM (which sheet) + WHERE (what filter to apply).
⚡ Live Interactive SQL Sandbox (Browser Engine)
AlaSQL Engine ActiveTest and run live SQL queries right in your browser! Click any of the quick buttons below or type your SQL code and press Run Query (Ctrl + Enter):
🗄️ Active Sandbox Data Tables (Sample Dataset)
Sheet 1: Customers 4 Rows
| CustomerID | CustomerName | City | Country |
|---|---|---|---|
| 1 | Amit Sharma | Delhi | India |
| 2 | Pooja Verma | Mumbai | India |
| 3 | John Miller | Berlin | Germany |
| 4 | Sara Smith | London | UK |
Sheet 2: Employees 4 Rows
| EmpID | Name | dept_id | Salary |
|---|---|---|---|
| 101 | Rahul Roy | 10 | 65000 |
| 102 | Sneha Rao | 20 | 48000 |
| 103 | Vikas Jain | 10 | 72000 |
| 104 | Karan Mehta | NULL | 42000 |
Sheet 3: Products 4 Rows
| ProductID | ProductName | Price | SupplierID |
|---|---|---|---|
| 1 | Mechanical Keyboard | 45 | 1 |
| 2 | Gaming Mouse | 25 | 1 |
| 3 | HD Monitor | 180 | 2 |
| 4 | USB Hub | 15 | 3 |
1. SQL Basics & Queries (Essential Everyday Commands)
SQL SELECT & FROM
Fetch and view specific columns from a sheet.
* (star) to retrieve all columns.
SQL SELECT DISTINCT
Retrieve only unique values and remove duplicate entries.
SQL WHERE
Filter rows based on specified conditions.
SQL AND, OR, NOT
Combine multiple conditions simultaneously.
SQL ORDER BY
Sort data in ascending or descending order.
SQL INSERT INTO
Insert a brand-new row of data into a sheet.
SQL UPDATE
Modify and update existing data in a table.
SQL DELETE
Permanently remove specific rows from a table.
SQL LIMIT / TOP
Fetch only a specified number of initial records.
SQL NULL Values
Check for blank or missing values.
IS NULL instead of = NULL.
2. SQL Aggregate Functions (Automated Calculations & Metrics)
SQL MIN() & MAX()
Find the smallest and largest numbers in a column.
SQL COUNT(), SUM(), AVG()
Count total records, compute the sum, and calculate the average.
3. Advanced Querying & Joins (Smart Search & Combining Sheets)
SQL LIKE & Wildcards (%)
Search records by matching prefix, suffix, or substrings.
SQL BETWEEN & IN
Filter within a numeric/date range or a discrete list of values.
SQL Aliases (AS)
Temporarily rename columns or tables for cleaner presentation.
cust_first_nm, but on screen we display it neatly as Client_Name.
SQL INNER JOIN
Combine two different sheets using a common ID column.
dept_id merges them into one combined view!
SQL GROUP BY & HAVING
Group data into clusters and calculate summary metrics.
SQL CASE Statement
Apply conditional logic (IF-THEN-ELSE) directly in queries.
SQL COALESCE / IFNULL
Display a default number or text whenever a value is NULL.
SQL UNION
Combine two separate query outputs into one unified list.
4. Database & Table Management (Creating & Modifying Structures)
SQL CREATE TABLE
Create a brand-new empty table (sheet).
SQL ALTER TABLE
Add, modify, or drop columns in an existing table.
SQL Primary Key
A unique identification constraint for each record.
SQL AUTO_INCREMENT
Automatically generates sequential IDs (1, 2, 3...) with each new entry.
5. Stored Procedures & Security (Shortcuts & Data Protection)
SQL Stored Procedure
Save a complex query under a reusable shortcut name.
SQL Comments (--)
Add explanatory notes to code for documentation.
Q1: How do you find the 2nd Highest Salary in an Employee table?
Most Frequent #1Q2: How do you find duplicate records in a table?
Data CleaningGROUP BY on the column(s) and filtering with HAVING COUNT(*) > 1, duplicate entries are isolated:
Q3: What is the exact difference between DELETE, TRUNCATE, and DROP?
Core Concept| Feature | DELETE (DML) | TRUNCATE (DDL) | DROP (DDL) |
|---|---|---|---|
| Action / Function | Removes rows individually | Flushes all rows instantaneously | Deletes entire table and its schema definition |
| WHERE Clause | Yes (filter specific rows) | No (clears entire table) | No |
| Rollback | Yes (logged per row, rollback-safe) | No / Engine-dependent | No (permanent deletion) |
| Speed | Slower (generates per-row logs) | Very Fast (deallocates storage pages) | Fastest |
Q4: Find customers who NEVER placed any order (Unmatched Records).
Joins & SubqueriesQ5: What is a SELF JOIN and when do we use it? (Manager-Employee Hierarchy)
Advanced Joine for employee, m for manager) is called a SELF JOIN:
Q6: What is the difference between WHERE and HAVING clause?
Fundamental FilterSUM() or AVG().• HAVING: Filters grouped summaries after
GROUP BY has aggregated the records (e.g., HAVING COUNT(*) > 2).
Q7: What is the difference between PRIMARY KEY and UNIQUE KEY?
Schema Design2. NULL Value: Primary key can never be
NULL. Unique keys allow NULL values (typically one or multiple, depending on the database engine).3. Usage: Primary Key defines row identity (e.g., Roll No, UUID). Unique key ensures uniqueness for auxiliary data (e.g., Email, Phone Number).
Q8: What is the difference between ROW_NUMBER(), RANK(), and DENSE_RANK()?
Window Functions- ROW_NUMBER(): Assigns strictly consecutive unique numbers:
1, 2, 3, 4(ignores ties). - RANK(): Assigns identical ranks to ties, then skips subsequent rank numbers:
1, 2, 2, 4(rank 3 skipped!). - DENSE_RANK(): Assigns identical ranks to ties, with no gaps in ranking sequence:
1, 2, 2, 3.
Q9: What is SQL Injection and how do you protect against it?
Security & Best Practices' OR '1'='1) alters query execution to bypass authentication or extract sensitive data.Defense: Never concatenate raw user input into SQL queries. Always use Parameterized Queries (Prepared Statements) where inputs are handled strictly as parameters, not executable code.
Q10: What is a Database INDEX, and what are its pros and cons?
Performance Tuning• Pros:
SELECT and WHERE search speeds increase by 100x+.• Cons: Write operations (
INSERT/UPDATE/DELETE) require index updates, adding write overhead and consuming extra disk storage.
📁 The 3 Interconnected Database Tables in this Project (Database Schema):
1. Users (Customers) 5 Rows
| user_id | name | city |
|---|---|---|
| 1 | Aman Gupta | Delhi |
| 2 | Riya Sen | Mumbai |
| 3 | Kabir Das | Delhi |
| 4 | Neha Sharma | Bangalore |
| 5 | Varun Joshi | Jaipur |
2. Items (Products) 4 Rows
| item_id | title | price (₹) |
|---|---|---|
| 101 | Wireless Earbuds | 1200 |
| 102 | Fast Charger | 500 |
| 103 | Smart Watch | 2500 |
| 104 | Laptop Stand | 800 |
3. Orders (Sales Records) 5 Rows
| order_id | user_id | item_id | status |
|---|---|---|---|
| 501 | 1 | 101 | Delivered |
| 502 | 2 | 103 | Delivered |
| 503 | 1 | 102 | Delivered |
| 504 | 3 | 103 | Cancelled |
| 505 | 4 | 104 | Delivered |
WHERE price >= 1000 filtered out lower-priced items (500 and 800), and ORDER BY price DESC placed the highest-priced Smart Watch (2500) at the top.
INNER JOIN joined Orders and Items on item_id to fetch item prices. WHERE status = 'Delivered' excluded cancelled orders, calculating exact net sales of ₹5,000.
Orders at the center, joining Users on one side and Items on the other, creating a comprehensive invoice dataset.
GROUP BY u.city created city clusters and SUM(i.price) aggregated the sales for each cluster. Mumbai ranked #1 with ₹2,500.
LEFT JOIN ensured customers with zero orders (Varun Joshi) were not dropped.2.
COALESCE safely converted empty amounts to 0.3.
CASE applied automated customer tier tags!