Score 80%+ in the Final Exam to earn your Certificate
- โ The entire course is free
- ๐ 80%+ in the Final Exam = Certificate
- ๐ 50 Questions
๐งญ Never seen SQL before? Just understand these 4 things!
SQL is not hard programming. Imagine you have an Excel Sheet open and you are typing out instructions telling it what to do:
SELECT (what to see) + FROM (from which sheet) + WHERE (what the filter is).
โก Live Interactive SQL Sandbox (Browser Engine)
AlaSQL Engine ActiveHere you can run live SQL queries! Click the quick buttons below, or write your own SQL code and press Run Query (Ctrl + Enter):
๐๏ธ Active Sandbox Data Tables (Our Sample Data)
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 (Everyday Basic Commands)
SQL SELECT & FROM
Pull out just the columns you want from the sheet.
* (star). Very simple.
SQL SELECT DISTINCT
Remove repeated values and see only the unique ones.
SQL WHERE
Add a condition and get only the rows that match it.
SQL AND, OR, NOT
Combine more than one condition together.
SQL ORDER BY
Arrange data from smallest to largest or the other way round.
SQL INSERT INTO
Add a brand new row to the table.
SQL UPDATE
Fix data that is wrong without touching the rest of the table.
SQL DELETE
Remove a row from the table for good.
SQL LIMIT / TOP
See only the first few records. (LIMIT in MySQL / PostgreSQL / SQLite, TOP in SQL Server / MS Access)
SQL NULL Values
Check whether a box is empty or not.
IS NULL, not = NULL.
2. SQL Aggregate Functions (Automatic Maths and Totals)
SQL MIN() & MAX()
Find the smallest and the largest number.
SQL COUNT(), SUM(), AVG()
Find how many there are, the total, and the average.
3. Advanced Querying & Joins (Smart Search and Joining Two Sheets)
SQL LIKE & Wildcards (%)
Search by the first or last letters of a name.
SQL BETWEEN & IN
Search within a range, or among a few chosen options.
SQL Aliases (AS)
Give a column a new, nicer name, that's all.
cust_first_nm, but on screen you want to show Client_Name. That is what an alias does.
SQL INNER JOIN
Join two separate sheets using a common ID.
dept_id and you get one big table. That is JOIN.
SQL GROUP BY & HAVING
Make groups of rows with the same values and get a summary.
SQL CASE Statement
Make decisions based on a condition, i.e. if-else.
SQL COALESCE / IFNULL
Show a default value in place of an empty (NULL) spot.
SQL UNION
Stack two lists one below the other into one long list.
4. Database & Table Management (Creating a New File and Sheet)
SQL CREATE TABLE
Create a brand new empty table.
SQL ALTER TABLE
Add a new column to an existing table, or remove one.
SQL Primary Key
An ID number that uniquely identifies each row.
SQL AUTO_INCREMENT / IDENTITY
The ID goes up by itself, 1, 2, 3, with every new entry. (AUTO_INCREMENT in MySQL, IDENTITY in SQL Server)
5. Stored Procedures & Security (Shortcuts and Security)
SQL Stored Procedure
Save a big query under a name so you don't have to type it again. (CALL in MySQL, EXEC in SQL Server)
DELIMITER is changed so that the ; inside the procedure does not cut the whole command short. CALL also works in PostgreSQL (11+), but the way the procedure body is written is different.
SQL Comments (--)
Leave a note for yourself next to the code.
GROUP BY on a column and check HAVING COUNT(*) > 1, all the duplicate records come out:
| Feature | DELETE (DML) | TRUNCATE (DDL) | DROP (DDL) |
|---|---|---|---|
| What it does | Removes rows one by one | Empties all rows in one go | Deletes both the table and its structure |
| WHERE Clause | Yes (can filter specific rows) | No (the whole sheet is cleared) | No |
| Rollback | Yes (can be rolled back within a transaction) | No (very difficult / engine dependent) | No (permanently deleted) |
| Speed | Slow (every row is logged) | Very Fast (de-allocates storage) | Fastest |
e and m) is called a SELF JOIN:
SUM() and AVG() cannot be used in it.โข HAVING: Filters the calculated summary after
GROUP BY has been applied (e.g. HAVING COUNT(*) > 2).
2. NULL Value: A primary key can never be
NULL, but a unique key allows NULL.3. Usage: A Primary Key identifies the row. A unique key is for extra unique data.
- ROW_NUMBER(): Always gives consecutive, distinct numbers:
1, 2, 3, 4. - RANK(): Repeats the rank on a tie, then skips the next number:
1, 2, 2, 4. - DENSE_RANK(): Repeats the rank on a tie and does not skip any number:
1, 2, 2, 3.
' OR '1'='1 into a login form and accesses data without a password.Defense: Always use Parameterized Queries (Prepared Statements).
โข Pros:
SELECT and WHERE search speed can become up to 100x faster.โข Cons: Write operations (
INSERT/UPDATE) become slightly slower and extra storage is needed.
๐ 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 (Items) 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 Record) 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 |