My learning.

Find a course, enrol, and finish it with a verifiable certificate.

SQL Basics – Querying Databases

Foundational SQL from SELECT to joins and aggregation.

3 lessonsOffice & Data SkillsFree to enrol

Lessons

01

What is SQL and Why Use It?

Video: enrol to watch
SQL (Structured Query Language) is the standard language for asking questions of data held in a relational database. Instead of scrolling through a spreadsheet, you describe what you want and the database returns it. Key ideas - A database holds tables. A table has columns (fields, such as customer_name) and rows (records, one per customer). - Tables relate to one another through shared keys, which is why it is called a relational database. - SQL is declarative: you state what you want, not how to go and fetch it. Your first query SELECT customer_name, city FROM customers; SELECT names the columns you want back. FROM names the table they come from. The semicolon ends the statement. To see every column, use the asterisk: SELECT * FROM customers; Use SELECT * while you are exploring a table, but name columns explicitly in real work. It is faster, and it will not silently change behaviour when someone adds a column later. Returning only the first rows SELECT customer_name FROM customers LIMIT 10; LIMIT matters once a table holds millions of rows. Note that SQL Server uses SELECT TOP 10 instead, one of the few places where database products genuinely differ on basics. Why analysts reach for SQL instead of a spreadsheet - It handles volumes a spreadsheet cannot even open. - The query is a written record of exactly how a number was produced, so it can be re-run, reviewed and corrected. - It runs against the live database, so the answer reflects today's data rather than last month's export. Practice Write a query that returns only the product_name and price columns from a products table, limited to the first 20 rows.
02

Filtering Rows with WHERE

Video: enrol to watch
WHERE narrows a query down to the rows you actually care about. It goes after FROM, and before any grouping or sorting. SELECT customer_name, city FROM customers WHERE city = 'Dubai'; Comparison operators = (equal), <> or != (not equal), >, <, >=, <= Text values go inside single quotes; numbers do not: SELECT * FROM orders WHERE total > 500; Combining conditions SELECT * FROM orders WHERE total > 500 AND status = 'shipped'; AND is evaluated before OR, so always use brackets when you mix the two, or you will quietly get the wrong rows back: SELECT * FROM orders WHERE (status = 'shipped' OR status = 'delivered') AND total > 500; Useful shorthands - IN matches any value in a list: WHERE city IN ('Dubai', 'Abu Dhabi', 'Sharjah') - BETWEEN covers an inclusive range: WHERE order_date BETWEEN '2026-01-01' AND '2026-03-31' - LIKE matches patterns, where % stands for any run of characters: WHERE customer_name LIKE 'A%' finds names beginning with A Missing values: the most common beginner trap An empty value in SQL is NULL, which means unknown rather than zero or blank. Comparing anything to NULL with = never matches, not even NULL = NULL. Use IS NULL instead: -- wrong: returns no rows at all SELECT * FROM customers WHERE phone = NULL; -- correct SELECT * FROM customers WHERE phone IS NULL; The same applies in reverse with IS NOT NULL. This single rule accounts for a large share of "my query returns nothing and I cannot see why" problems. Practice Write a query returning orders placed during 2026 with a total of at least 1,000, excluding any order whose status is 'cancelled'.
03

GROUP BY & Aggregate Functions

Video: enrol to watch
Aggregate functions collapse many rows into a single summary value. - COUNT(*) counts rows - SUM(column) adds values together - AVG(column) gives the mean - MIN(column) and MAX(column) give the smallest and largest SELECT COUNT(*) AS order_count, SUM(total) AS revenue FROM orders; That returns one row covering the whole table. GROUP BY splits the result into one row per group: SELECT city, COUNT(*) AS order_count, SUM(total) AS revenue FROM orders GROUP BY city; The rule worth memorising: every column in SELECT must either appear in GROUP BY or sit inside an aggregate function. Breaking it is the error beginners hit most often. Grouping by several columns gives one row per combination: SELECT city, status, COUNT(*) AS order_count FROM orders GROUP BY city, status; WHERE versus HAVING WHERE filters individual rows before grouping happens. HAVING filters the groups afterwards. You cannot put an aggregate inside WHERE. -- cities with more than 100 orders SELECT city, COUNT(*) AS order_count FROM orders GROUP BY city HAVING COUNT(*) > 100; Both together, in the order the database applies them: SELECT city, SUM(total) AS revenue FROM orders WHERE status <> 'cancelled' -- drop cancelled rows first GROUP BY city -- then group what is left HAVING SUM(total) > 50000 -- then keep only high-revenue cities ORDER BY revenue DESC; One subtlety worth knowing: COUNT(*) counts every row, while COUNT(column) skips rows where that column is NULL. The two can legitimately disagree, and which one you want depends on whether you are counting records or counting answers. Practice Write a query returning each product category, its number of orders and its average order value, for 2026 only, showing just the categories that average above 250.

Related courses

All courses