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:

SELECT title
FROM books
WHERE author = 'JK Rowling'
Processing Query...

1 Finding Nemo's Friends

We have a table called fish. We want to find only the **Orange** fish.

SQL Query
SELECT name, species
FROM fish
WHERE color = 'Orange'
Result
name species
Nemo Clownfish
Marlin Clownfish
* "Dory" (Blue) was filtered out.
Keywords:
  • 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

Table: bookings
hotel nights price
Ritz 5 500
Hostel 2 50
Plaza 4 300
The Code
SELECT hotel, price
FROM bookings
WHERE nights > 3
ORDER BY price
Which rows will appear? And in what order?

3 Mission Control

Current Database: users
id name role score
Bronze Badge

Select All

Retrieve all columns from the users table.

Silver Badge

Admin Filter

Find only users where role is 'Admin'.

Gold Badge

High Scorers

Find name and score where score > 100, ordered by score.

query.sql Ready