SQL for beginners: learn SQL basics from scratch
SQL for beginners is easier to learn when every new concept becomes a small query. Start with SELECT, WHERE, and ORDER BY, then move on to joins, aggregates, grouping, and more complex query patterns.
Updated · SQL Arena team
What you will practice
- Select specific columns with SELECT
- Filter rows with WHERE
- Sort query results with ORDER BY
- Connect related tables with JOIN
- Build toward COUNT, SUM, AVG, and GROUP BY
A practice problem in the trainer
This is how a problem looks in SQL Arena: the task, the editor, the result and the database schema.
You have a category table and a product table. Return product_name and price for products in the Electronics department priced at least 80. Show the most expensive products first.
SELECT p.product_name, p.price FROM products AS p JOIN categories AS c ON c.id = p.category_id WHERE c.department = 'Electronics' AND p.price >= 80 ORDER BY p.price DESC, p.product_id;
| # | product_name | price |
|---|---|---|
| 1 | Wide View | 349.00 |
| 2 | Office View | 219.00 |
| 3 | Studio Sound | 129.00 |
| 4 | Studio Keys | 89.00 |
You have a category table and a product table. Return product_name and price for products in the Electronics department priced at least 80. Show the most expensive products first.
SELECT p.product_name, p.price FROM products AS p JOIN categories AS c ON c.id = p.category_id WHERE c.department = 'Electronics' AND p.price >= 80 ORDER BY p.price DESC, p.product_id;
SQL for beginners: a query explained step by step
The SELECT list contains only p.product_name and p.price because those are the two fields the task asks for. This is a useful habit to develop early. SELECT * may feel convenient, but it often returns columns you do not need and makes it harder to see what the query is meant to produce.
The department is stored in categories, while the product name and price are stored in products. The JOIN connects them through categories.id and products.category_id. Once each product is matched to its category, WHERE can keep only rows from Electronics and then apply the price threshold of 80.
ORDER BY p.price DESC places the highest price first. The second sort key, product_id, makes the order deterministic if two products share the same price. The final output contains four products and demonstrates several core building blocks at once: selecting columns, joining tables, filtering rows, and sorting results.
If you want to learn SQL from scratch, avoid trying to memorize the entire language at once. First learn how SELECT chooses columns, WHERE filters rows, and ORDER BY sorts the result. Next, add COUNT, SUM, AVG, and GROUP BY. Once those basics feel natural, move to JOINs and queries that combine multiple tables. This progression makes SQL easier to understand because each new feature solves a specific data problem instead of appearing as an isolated piece of syntax.
SELECT p.product_name, p.price FROM products AS p JOIN categories AS c ON c.id = p.category_id WHERE c.department = 'Electronics' AND p.price >= 80 ORDER BY p.price DESC, p.product_id;
| product_name | price |
|---|---|
| Wide View | 349.00 |
| Office View | 219.00 |
| Studio Sound | 129.00 |
| Studio Keys | 89.00 |
Common mistakes when learning SQL basics
Using a column from a table that was never joined
department belongs to categories, not products. A query cannot filter on that field until categories is part of the query. When a column seems unavailable, check the schema and identify the relationship between the tables.
Using OR instead of AND
department = 'Electronics' OR price >= 80 describes a different rule. It accepts every electronics product as well as expensive products from other departments. The task requires both conditions to be true, so AND is the correct operator.
Forgetting DESC
ORDER BY price sorts ascending by default, which puts the cheapest matching item first. DESC reverses that order when the task asks for the highest values first.
Practice problems on this topic
SQL from scratch courseOnce this query feels comfortable, split the skills into smaller exercises and repeat them on new schemas. SQL Arena includes free Easy tasks such as counting items in each basket, creating a basket representation for a log, selecting a preview without heavy columns, and finding the three largest receipts. Each exercise has its own tables, so practice is not tied to one memorized schema. Solutions are also checked against hidden data rather than a fixed visible output, which helps expose queries that only work by accident. SQL Arena contains 1,192 tasks. The free tier includes 292 tasks for PostgreSQL, MySQL, ClickHouse, and BigQuery, with no card required. Each dialect has a separate browser-based sandbox, so there is no database installation to configure before practicing. For a structured path, the “SQL from Scratch” course has 12 chapters and 77 lessons, including 16 free lessons. It starts with foundational query building and connects theory with a task inside each lesson. When you need help understanding an error, the AI mentor can provide hints and explanations; 10 uses are available for free. ER diagrams can help you understand unfamiliar table relationships, while EXPLAIN becomes useful later when you begin looking at how queries execute. There are also 12 task tracks organized around professional practice.
Reference on this topic
In-depth articles with syntax and examples in the SQL Arena reference.
Frequently asked questions
How to learn SQL for beginners?
Start with simple SELECT queries and practice filtering and sorting data. Then add aggregates, GROUP BY, joins, subqueries, and window functions as your queries become more complex.
Is SQL hard to learn?
Basic SQL is relatively approachable because many queries use a small set of readable commands. The harder part is learning how tables relate, how rows change after joins, and how to structure solutions for more complex problems.
What SQL basics should a beginner learn first?
Learn tables, rows, columns, SELECT, WHERE, and ORDER BY first. After that, focus on aggregate functions, GROUP BY, and JOIN because they form the foundation for many practical queries.
How long does it take to learn SQL basics?
There is no fixed duration because it depends on prior experience and practice frequency. You can understand basic syntax fairly quickly, but becoming comfortable with joins, grouping, and query reasoning requires repeated practice.
What should I practice when learning SQL?
Practice selecting columns, filtering rows, sorting results, calculating aggregates, and joining related tables. It is useful to solve the same type of problem with slightly different schemas so you learn the concept rather than one memorized query.
Learn SQL for beginners through practice
Follow the course if you want the fundamentals in a clear sequence, or open the free Easy exercises and practice writing SELECT, WHERE, ORDER BY, aggregates, and joins on fresh datasets.
Start SQL PracticeMore practice from CodeRang
- Python ArenaPython Arena has 1300+ Python 3.12 problems covering functions, classes, async code and technical interview tasks.1300+ tasks · Python 3.12
- Playwright ArenaPlaywright Arena has 30 JavaScript and E2E problems where you write a test and immediately see what it did in the browser.30 tasks · JavaScript / E2E