The Data Detective
SQL (Structured Query Language) is how we talk to databases.
Instead of searching manually, we
ask for exactly what we want.
The Concept
Imagine a library with millions of books.
Without SQL: You walk through every aisle, checking every spine to find "Books by JK Rowling". (Slow!)
With SQL: You ask the librarian:
FROM books
WHERE author = 'JK Rowling'
1 Finding Nemo's Friends
We have a table called fish. We want to find only the **Orange** fish.
FROM fish
WHERE color = 'Orange'
| name | species |
|---|---|
| Nemo | Clownfish |
| Marlin | Clownfish |
SELECT: Which columns (attributes) you want to see.FROM: Which table (collection) to look in.WHERE: Filter criteria (only rows that match).
2 Predict the Result
| hotel | nights | price |
|---|---|---|
| Ritz | 5 | 500 |
| Hostel | 2 | 50 |
| Plaza | 4 | 300 |
FROM bookings
WHERE nights > 3
ORDER BY price
| Plaza | 300 |
| Ritz | 500 |
1. Filter: Keeps 'Ritz' (5) and 'Plaza' (4). 'Hostel' (2) is
removed.
2. Sort: 'Plaza' (300) comes before 'Ritz' (500).
3 Mission Control
users
| id | name | role | score |
|---|
Select All
Retrieve all columns from the users table.
Admin Filter
Find only users where role is 'Admin'.
High Scorers
Find name and score where score >
100, ordered by score.