~/articles/sql-for-beginners-part-1.md
type: SQL read_time: 6 min words: 1050
SQL

SQL for Beginners – Part 1: Understanding SELECT and Basic Queries

// Learn the fundamentals of SQL SELECT statements, filtering, sorting and limiting results. Ideal for UK data analysts starting their SQL journey.

Introduction

SQL (Structured Query Language) is the lingua franca of data stored in relational databases. Whether you’re analysing retail sales in Manchester, tracking patient records for the NHS, or building dashboards for a fintech start‑up in London, the ability to retrieve the right data quickly is essential.

In this first part of the SQL for Beginners series we focus on the most important command in any analyst’s toolkit – the SELECT statement. You’ll discover how to:

  • Pull whole tables or specific columns
  • Filter rows with WHERE
  • Remove duplicates using DISTINCT
  • Sort results with ORDER BY
  • Limit output with TOP/LIMIT

By the end of the article you’ll be comfortable writing basic queries that return clean, structured data ready for visualisation in Power BI, Tableau or Python.

Why it matters: According to IT Jobs Watch, the median daily rate for SQL Data Analyst contractors in the UK is £429 (Nov 2025). Mastering SELECT is the first step toward those high‑paying roles.


1. The Anatomy of a SELECT Statement

A minimal SELECT query looks like this:

SELECT *
FROM Customers;
  • SELECT – tells the database what to return.
  • * – a wildcard meaning “all columns”.
  • FROM – specifies the table (or view) to query.

Selecting Specific Columns

Returning every column can be wasteful, especially when tables contain dozens of fields. Choose only what you need:

SELECT CustomerName, City, Country
FROM Customers;

Benefits: Faster query execution, reduced network traffic, and clearer downstream analysis.*


2. Filtering Rows with WHERE

The WHERE clause narrows results based on logical conditions.

Simple Equality

SELECT CustomerName, City
FROM Customers
WHERE Country = 'Germany';

Comparison Operators

Operator Meaning
= equal
<> or != not equal
< > less / greater than
<= >= less‑or‑equal / greater‑or‑equal

Combining Conditions

Use AND and OR to build complex filters:

SELECT CustomerName, City, PostalCode
FROM Customers
WHERE Country = 'UK' AND PostalCode LIKE 'SW%';

LIKE enables pattern matching with % (any sequence) and _ (single character).


3. Removing Duplicates with DISTINCT

Sometimes a column contains repeated values. DISTINCT returns each unique value once.

SELECT DISTINCT Country
FROM Customers;

Result: a list of every country represented in the Customers table, without repeats.


4. Sorting Results with ORDER BY

ORDER BY arranges rows in ascending (ASC) or descending (DESC) order.

SELECT CustomerName, City, Country
FROM Customers
WHERE Country = 'USA'
ORDER BY City ASC, CustomerName DESC;

Tip: If you omit ASC/DESC, the default is ascending.


5. Limiting Output: TOP vs LIMIT

Large tables can return thousands of rows, which may be unnecessary for a quick check.

SQL Server / Azure (TOP)

SELECT TOP 10 *
FROM Sales
ORDER BY SaleDate DESC;

MySQL / PostgreSQL (LIMIT)

SELECT *
FROM Sales
ORDER BY SaleDate DESC
LIMIT 10;

Both statements fetch the ten most recent sales. Use the appropriate syntax for your database engine.


6. Practical Example: A Mini‑Report

Imagine you’re a data analyst at a mid‑size e‑commerce firm. You need a snapshot of the top‑selling products in the last month, including the total quantity sold.

SELECT TOP 5
    p.ProductName,
    SUM(od.Quantity) AS TotalUnits,
    SUM(od.Quantity * od.UnitPrice) AS Revenue
FROM OrderDetails od
JOIN Products p ON od.ProductID = p.ProductID
JOIN Orders o ON od.OrderID = o.OrderID
WHERE o.OrderDate >= DATEADD(MONTH, -1, GETDATE())
GROUP BY p.ProductName
ORDER BY TotalUnits DESC;

Key points illustrated:

  • JOINs – combine data from multiple tables.
  • Aggregate functions (SUM) – calculate totals.
  • GROUP BY – groups rows by product before aggregating.
  • ORDER BY – ranks products by units sold.

Even though aggregates belong to Part 2 of the series, this example shows how SELECT works hand‑in‑hand with other clauses.


7. Common Pitfalls for Beginners

Pitfall Why it Happens How to Avoid
Forgetting FROM Confusing SELECT with a function call Always include FROM <table>
Using SELECT * in production Returns unnecessary columns, slows queries List only required columns
Mis‑using LIKE without wildcards Returns exact matches only Add % or _ as needed
Ignoring case sensitivity Some DBMS (e.g., PostgreSQL) treat identifiers case‑sensitively Use consistent casing or double‑quote identifiers
Overlooking NULL handling WHERE Column = NULL never matches Use IS NULL or IS NOT NULL

8. Quick Reference Cheat‑Sheet

-- 1. All columns
SELECT * FROM TableName;

-- 2. Specific columns
SELECT col1, col2 FROM TableName;

-- 3. Filter rows
SELECT * FROM TableName WHERE col1 = 'value';

-- 4. Distinct values
SELECT DISTINCT col1 FROM TableName;

-- 5. Sort rows
SELECT * FROM TableName ORDER BY col1 DESC, col2 ASC;

-- 6. Limit rows (MySQL/PostgreSQL)
SELECT * FROM TableName LIMIT 20;

-- 7. Top rows (SQL Server)
SELECT TOP 20 * FROM TableName;

Bookmark this snippet for a rapid refresher while you’re writing queries.


9. From Learning to Earning: The UK Data Analyst Landscape

Understanding SELECT is a gateway to roles that demand strong SQL proficiency. Recent market data (IT Jobs Watch, Nov 2025) shows:

  • Median contractor daily rate: £429 (down 14 % YoY, still competitive).
  • Top locations: London (£429), South England (£450), and Scotland (£375).
  • In‑demand skills alongside SQL: Python (65 %), Power BI (34 %), Tableau (22 %).

If you can confidently write SELECT queries, you’ll be well‑positioned to add these complementary skills and command higher rates.


Conclusion

The SELECT statement is the backbone of data retrieval in relational databases. By mastering column selection, filtering, deduplication, sorting, and limiting, you gain the ability to extract exactly the data you need – a skill that directly translates into higher‑paying analyst roles across the UK.

In the next part of this series we’ll dive deeper into aggregations, GROUP BY and JOINs, unlocking the full analytical power of SQL. Until then, practise the queries above on a sample database (e.g., the classic Northwind or AdventureWorks datasets) and build confidence in your new SQL toolkit.

Happy querying!