luvv to helpDiscover the Best Free Online Tools
Topic 3 of 12

Selecting Data With Select

Learn Selecting Data With Select for free with explanations, exercises, and a quick test (for Business Analyst).

Published: December 20, 2025 | Updated: December 20, 2025

Who this is for

Business Analysts and aspiring analysts who need to pull specific columns and rows from databases to answer business questions quickly.

Prerequisites

  • Know what a table, row, and column are.
  • Be able to open a SQL editor connected to a practice database (any SQL dialect is fine).
  • Comfort reading simple datasets (no prior coding required).

Why this matters

Most analyst tasks start with a SELECT. Examples:

  • Pull a customer list to email only active users in New York.
  • Check top 10 highest-value orders this month.
  • Export just the columns needed for a dashboard (e.g., order_date, revenue, channel).

If you can confidently use SELECT, you can explore data, validate assumptions, and provide answers fast.

Concept explained simply

SELECT picks columns; FROM picks the table; WHERE filters rows; ORDER BY sorts; LIMIT/FETCH reduces how many rows you see; DISTINCT removes duplicates; aliases (AS) rename columns for readability.

Mental model

Imagine a spreadsheet. FROM chooses the sheet. SELECT chooses the columns you want to view. WHERE hides rows that don’t match your rule. ORDER BY sorts the visible rows. LIMIT shows only the first N rows.

Notes on SQL differences
  • LIMIT n is common in PostgreSQL/MySQL; in SQL Server use TOP n; in standard SQL use FETCH FIRST n ROWS ONLY.
  • Aliases can be written as AS alias or just alias.

Mini cheatsheet

-- Pick columns
SELECT column1, column2
FROM table;

-- Rename output columns
SELECT column1 AS readable_name
FROM table;

-- Remove duplicates
SELECT DISTINCT city
FROM customers;

-- Filter rows
SELECT *
FROM orders
WHERE status = 'Shipped';

-- Sort
SELECT order_id, total_amount
FROM orders
ORDER BY total_amount DESC;

-- Limit rows
SELECT *
FROM orders
FETCH FIRST 5 ROWS ONLY; -- or LIMIT 5 / TOP 5 depending on SQL

-- Calculated column
SELECT quantity * unit_price AS line_total
FROM order_items;

Worked examples

Example 1: Pick only needed columns

SELECT customer_id, full_name AS customer_name
FROM customers;

Why: Export a clean list without extra fields.

Example 2: Filter then sort

SELECT order_id, order_date, total_amount
FROM orders
WHERE order_date >= '2025-01-01'
ORDER BY total_amount DESC;

Why: See recent high-value orders first.

Example 3: Create a calculated column

SELECT order_id, product, quantity * unit_price AS line_total
FROM order_items
WHERE quantity * unit_price >= 50
ORDER BY line_total DESC;

Why: Quickly estimate revenue contribution by line.

Example 4: Unique values only

SELECT DISTINCT city
FROM customers
ORDER BY city;

Why: Build a filter list for a dashboard.

Practice dataset (for exercises)

Use these small tables and rows to reason about expected results:

customers
customer_id | full_name | city
----------- | --------- | --------
1           | Alice     | New York
2           | Ben       | Chicago
3           | Cara      | New York
orders
order_id | customer_id | order_date  | status    | total_amount
-------- | ----------- | ----------- | --------- | ------------
101      | 1           | 2025-01-05  | Shipped   | 120.00
102      | 2           | 2025-01-07  | Pending   | 75.00
103      | 1           | 2025-02-02  | Shipped   | 200.00
104      | 3           | 2025-02-10  | Cancelled | 50.00
order_items
order_id | product   | quantity | unit_price
-------- | --------- | -------- | ----------
101      | Notebook  | 2        | 20.00
101      | Pen       | 5        | 4.00
103      | Backpack  | 1        | 80.00
103      | Notebook  | 3        | 20.00
102      | Pen       | 10       | 4.00
104      | Sticker   | 10       | 5.00

Exercises

Do these in order. Check your work with the expected output.

Exercise 1 — Unique cities

Get a list of unique customer cities in alphabetical order.

-- Write your query here
-- Use: SELECT, DISTINCT, FROM, ORDER BY
Exercise 2 — Shipped order totals

Show order_id and total_amount for Shipped orders only, highest amount first. Return only the top 2 rows.

-- Write your query here
-- Use: SELECT, FROM, WHERE, ORDER BY, LIMIT/FETCH/TOP
Exercise 3 — Big line totals

List order_id, product, and line_total where line_total > 50, sorted descending by line_total. Name the calculated column line_total.

-- Write your query here
-- Use: SELECT, FROM, WHERE (with expression), ORDER BY, alias

Exercise checklist

  • You selected only the needed columns (avoid SELECT * unless exploring).
  • You used DISTINCT when removing duplicates.
  • You applied WHERE before ORDER BY in your thinking.
  • You named calculated columns with clear aliases.
  • You limited preview rows when not all are needed.

Common mistakes and self-check

  • Using SELECT * in final queries: Self-check by listing exactly which columns stakeholders need.
  • Forgetting ORDER BY when asking for “top” or “first” rows: Self-check that your limit is paired with ORDER BY on the right metric.
  • Filtering after limiting: LIMIT doesn’t filter; it truncates. Apply WHERE first.
  • Unnamed calculated columns: Add AS to label new columns (line_total, revenue_usd).
  • Assuming LIMIT works everywhere: If your query tool errors, try FETCH FIRST n ROWS ONLY or TOP n.

Practical projects

  • Customer city snapshot: Create a clean list of unique cities with a column renamed to city_name.
  • Weekly order preview: Show the 10 most recent orders with order_id, order_date, total_amount.
  • High-value lines: Output order_id, product, line_total for lines over 100, sorted by line_total desc.

Learning path

  • Next: Filtering rows (WHERE, IN, BETWEEN, LIKE).
  • Then: Sorting and limiting (ORDER BY, LIMIT/FETCH/TOP, NULLS handling).
  • After: Aggregations (COUNT, SUM) and GROUP BY.
  • Later: Joining tables.

Mini challenge

Show the three highest total_amount shipped orders with columns: order_id, total_amount, plus a new column named tag that always shows the text 'priority'.

Reveal an example approach
SELECT order_id,
       total_amount,
       'priority' AS tag
FROM orders
WHERE status = 'Shipped'
ORDER BY total_amount DESC
FETCH FIRST 3 ROWS ONLY; -- or LIMIT 3 / TOP 3

Next steps

Take the Quick Test to lock in the basics. Note: The test is available to everyone; only logged-in users have their progress saved.

Practice Exercises

3 exercises to complete

Instructions

From customers, return a unique list of cities sorted alphabetically.

-- Use: SELECT DISTINCT ... FROM ... ORDER BY ...
Expected Output
city Chicago New York

Selecting Data With Select — Quick Test

Test your knowledge with 8 questions. Pass with 70% or higher.

8 questions70% to pass

Have questions about Selecting Data With Select?

AI Assistant

Ask questions about this tool