SQL Basics: Talking to Databases

Ask questions. Get answers. In one line.

1

Your First Query

SQL reads like English: "SELECT name FROM students WHERE grade > 80." Click each query to run it against the sample data and see the results.

2

Write Your Own Query

Type a SQL query and run it. Try SELECT, WHERE, ORDER BY, and LIMIT. The table has columns: id, name, age, grade, sport.

3

CRUD: The Four Operations

Every database application does four things: Create (INSERT), Read (SELECT), Update (UPDATE), Delete (DELETE). Together they are called CRUD.

CREATE (INSERT)

INSERT INTO students (name, age, grade) VALUES ("New Student", 15, 90). Adds a new row to the table.

READ (SELECT)

SELECT * FROM students WHERE id = 5. Reads data without changing it. The most common operation by far.

UPDATE

UPDATE students SET grade = 95 WHERE name = "Alice". Changes existing data. Always use WHERE or you update every row.

DELETE

DELETE FROM students WHERE grade < 50. Removes rows. Always use WHERE or you delete everything. There is no undo.

4

SQL Powers Everything

Nearly every application with persistent data uses SQL under the hood.

Social Media

SELECT * FROM posts WHERE user_id IN (SELECT following_id FROM follows WHERE user_id = me) ORDER BY created_at DESC. That is your feed.

E-Commerce

SELECT * FROM products WHERE category = "shoes" AND price < 100 ORDER BY rating DESC LIMIT 20. Search, filter, sort, paginate.

Analytics

SELECT country, COUNT(*) as users FROM signups GROUP BY country ORDER BY users DESC. One query, instant insights.

Fun Fact

SQL was invented at IBM in 1970 by Edgar Codd. It has been the standard database language for over 50 years. Despite dozens of "NoSQL" alternatives, SQL databases still power the vast majority of the world's data. MySQL, PostgreSQL, and SQLite are used by virtually every tech company.

SQL Developer!

You've written real SQL queries: SELECT to read, WHERE to filter, ORDER BY to sort, and INSERT to add data. Every app with a database uses these exact commands millions of times per day.

0
Queries Run
0
Time Exploring

SELECT Reads Data

SELECT name, age FROM users returns just those columns. SELECT * returns everything. This is the most common SQL command by far.

WHERE Filters Rows

WHERE age > 18 keeps only matching rows. You can combine conditions: WHERE age > 18 AND country = "US". The database scans and filters for you.

ORDER BY Sorts Results

ORDER BY score DESC sorts highest first. ASC sorts lowest first. Add LIMIT 10 to get only the top 10. Leaderboards are one query.

INSERT Adds Data

INSERT INTO users (name, age) VALUES ("Alice", 14) creates a new row. UPDATE changes existing rows. DELETE removes them. CRUD: Create, Read, Update, Delete.

Ready to Create?

Put your new knowledge into practice!

Suggest a Correction