evelin.

SELECT, filter and sort in SQL for clear beginner queries

Learn how to use SELECT, WHERE and ORDER BY in SQL to pick columns, filter rows and sort results so your data answers real questions.

What SELECT does and how to read query results

SELECT tells the database which columns you want to see. You read the result like a spreadsheet: each row is a record, each column is a field. As a beginner, focus on simple queries first, for example selecting a few key columns from one table. This helps you check what data you actually have before you try complex logic. Use SELECT * only while exploring a small table. For day to day work as a data analyst, it is better to name the columns you need, because this keeps queries readable and avoids surprises when tables change.

SELECT * vs explicit columns
SELECT *
  • •Quick for first exploration
  • •Returns all columns
  • •Harder to read in big tables
SELECT named columns
  • ✓Shows only what you need
  • ✓More stable when schema changes
  • ✓Clear for teammates and future you
VS

How to select specific columns from a table

In practice, you rarely want every column. Use SELECT with a comma separated list of columns and a FROM clause that names the table. Start with the business question, then think which columns help answer it, for example customer_id, order_date and total_amount. You can also rename columns with AS to make reports clearer. Be careful with typos in column names, because many SQL tools only show a blank column or error messages. Get into the habit of running and checking small queries, then extend them once you trust the output.

Steps to build a basic SELECT
  1. 📂1
    Name table
    Decide which table to query
  2. ✅2
    Pick columns
    List only columns you need
  3. 👀3
    Run and check
    Scan a few rows for sense

Filtering rows with WHERE for relevant data

WHERE limits which rows are returned so you see only relevant data. You can filter on text, numbers and dates with operators like =, >, <, BETWEEN, LIKE and IN. Combine conditions with AND for stricter filters and OR for broader ones. Order matters for your thinking, not for SQL, so use parentheses when logic gets complex. Typical beginner mistakes are forgotten quotes around text values and using OR where AND was intended. Always sanity check counts before and after adding a WHERE clause to see if the change matches your expectation.

Common WHERE operators
🔤
Text match
= and LIKE for names or codes
🔢
Number range
> , < , BETWEEN for amounts
📅
Date filters
BETWEEN and >= for time windows
🧩
Combining
AND and OR mix conditions

Sorting results with ORDER BY to see patterns

ORDER BY lets you decide how rows are sorted in the result set. Use ASC for ascending order or DESC for descending. A data analyst often sorts by date to see the latest events first or by a metric like revenue to find top or bottom performers. You can sort by several columns in sequence, for example by region and then by total_amount. A frequent mistake is to rely on the default order of results, which is not guaranteed. Always state your desired order in the query so your findings are repeatable and easy to verify.

Typical sort priorities
Date or time90%
Amount or score80%
Name or ID60%

Combining SELECT, WHERE and ORDER BY in real work

Most day to day queries mix these three pieces. You SELECT the columns that matter, use WHERE to filter to the time frame, product, region or user group, then ORDER BY to get a useful view. Think of it as moving from all rows to a focused and readable answer to a question. Keep queries simple at first, for example start without WHERE or ORDER BY and add them step by step. If a result looks wrong, remove one part at a time until it makes sense again, then rebuild the logic carefully.

Build a combined query
  1. 📋1
    Start with SELECT
    Choose table and columns
  2. 🎯2
    Add WHERE
    Filter to the needed rows
  3. 📊3
    Add ORDER BY
    Sort to reveal patterns
  4. 🔍4
    Review output
    Check counts and values

Real-world examples

  • • Your manager asks for a list of all customers who placed an order in the last 7 days, sorted by the highest order amount. You write a query that selects customer_id and order_total, filters with a WHERE condition on order_date and orders the results by order_total DESC.
  • • You want to check which support tickets remain open and have the oldest creation dates. You query the tickets table, select ticket_id, status and created_at, filter WHERE status = 'open' and ORDER BY created_at ASC so the longest waiting tickets appear first.

Useful links

Keep learning

Related courses

More programs on evelin that fit this path. Each one adapts to you after a two minute quiz.

Guides from related courses

All courses on evelin →

Turn reading into real progress

A short quiz builds your personal learning path for How to Become a Data Analyst. Lessons adapt to you from day one.

Start the quiz

Created with AI assistance and reviewed before publishing.