SQL & Data

SQL for Beginners: SELECT, WHERE and ORDER BY

Learn SQL from zero: how SELECT, WHERE and ORDER BY work, with a sample table, clear examples, common operators and beginner mistakes to avoid.

By DashCore Hub Editorial TeamUpdated 7 min read

SQL (Structured Query Language) is the language you use to ask a database for data, and three clauses do most of the work for beginners: SELECT chooses the columns, WHERE filters the rows and ORDER BY sorts the result. Learn these three well and you can already answer many everyday business questions, such as "which orders over $500 shipped to Florida last month?"

Why analysts learn SQL

Most company data lives in relational databases: sales systems, ERPs, e-commerce platforms and data warehouses. Excel and Power BI can connect to them, but SQL lets you pull exactly the rows and columns you need before the data ever reaches your report. That means smaller files, faster dashboards and fewer manual steps.

The good news is that basic SQL reads almost like English. The keywords are the same in PostgreSQL, MySQL, SQL Server, SQLite and cloud warehouses, with only small differences in some functions. If you are deciding which database to practice on, see our comparison of PostgreSQL vs MySQL vs SQL Server.

The sample table

All examples below use a simple table called orders:

order_idcustomerstateorder_dateamount
1001Ana RiveraFL2026-09-02320.00
1002Brooks MarketGA2026-09-051250.00
1003Coastal DeliFL2026-09-11780.50
1004Delta FoodsTX2026-09-1895.00
1005Evergreen CoFL2026-10-01540.00

You can recreate it in any free database (SQLite works fine on a laptop) and run every query yourself.

SELECT: choose your columns

Every query starts with SELECT followed by the columns you want, and FROM followed by the table:

SELECT customer, amount
FROM orders;

This returns two columns for all five rows. To get every column, use an asterisk:

SELECT *
FROM orders;

SELECT * is handy for exploring, but in reports list the columns explicitly. Your query becomes easier to read and doesn't break or slow down when someone adds new columns to the table.

Aliases and calculated columns

You can rename a column with AS and create new columns with arithmetic:

SELECT
    order_id,
    customer AS client_name,
    amount,
    amount * 0.07 AS estimated_tax
FROM orders;

To see each distinct value only once, add DISTINCT: SELECT DISTINCT state FROM orders; returns FL, GA and TX.

WHERE: filter your rows

WHERE keeps only the rows that meet a condition. Text and dates go inside single quotes; numbers don't.

SELECT order_id, customer, amount
FROM orders
WHERE state = 'FL';

This returns orders 1001, 1003 and 1005.

Common operators

OperatorMeaningExample
=, <>Equal, not equalstate <> 'TX'
>, <, >=, <=Comparisonsamount >= 500
BETWEENInside a range (inclusive)amount BETWEEN 100 AND 1000
INMatches any value in a liststate IN ('FL', 'GA')
LIKEText pattern; % means "anything"customer LIKE '%Foods%'
IS NULLMissing valueamount IS NULL

Combining conditions with AND and OR

SELECT order_id, customer, state, amount
FROM orders
WHERE state = 'FL'
  AND amount > 500
  AND order_date >= '2026-09-01';

This returns orders 1003 and 1005. When you mix AND and OR, use parentheses so the logic is clear: WHERE (state = 'FL' OR state = 'GA') AND amount > 500. Without them, AND is evaluated first and you can get unexpected rows.

Tip: To check for missing values, write IS NULL or IS NOT NULL. A condition like amount = NULL never matches anything, which is one of the most common beginner bugs.

ORDER BY: sort the result

ORDER BY sorts the rows. The default is ascending (ASC); add DESC for descending.

SELECT customer, state, amount
FROM orders
ORDER BY amount DESC;

You can sort by several columns. This query groups rows by state alphabetically, then shows the largest orders first inside each state:

SELECT customer, state, amount
FROM orders
ORDER BY state ASC, amount DESC;

Getting the top N rows

Limiting results is one place where databases differ:

-- PostgreSQL, MySQL, SQLite
SELECT customer, amount FROM orders ORDER BY amount DESC LIMIT 3;

-- SQL Server
SELECT TOP 3 customer, amount FROM orders ORDER BY amount DESC;

Putting it all together

Clauses must appear in this order: SELECT, FROM, WHERE, ORDER BY. Here is a realistic request from a sales manager: "Show me all Florida orders of $300 or more since September, biggest first."

SELECT
    order_id,
    customer,
    order_date,
    amount
FROM orders
WHERE state = 'FL'
  AND amount >= 300
  AND order_date >= '2026-09-01'
ORDER BY amount DESC;

Result: Coastal Deli (780.50), Evergreen Co (540.00) and Ana Rivera (320.00).

Behind the scenes, the database processes the query in a different order than you write it: it reads the table (FROM), filters the rows (WHERE), picks the columns (SELECT) and finally sorts (ORDER BY). That is why, in most databases, you can't use a column alias created in SELECT inside WHERE, but you can use it in ORDER BY.

Formatting and comments

SQL ignores extra spaces and line breaks, so use them to make queries readable. A common style is to write keywords in uppercase, put each clause on its own line and indent the column list. You can also leave notes for yourself or your teammates with comments: two dashes start a single-line comment, and /* ... */ wraps a multi-line one.

/* Florida orders report
   Requested by the sales team */
SELECT order_id, customer, amount   -- only the columns the report needs
FROM orders
WHERE state = 'FL';

Readable queries are easier to debug, easier to hand over to a colleague and easier to paste into Power BI or Excel when you connect to the database later. A good habit is to build a query step by step: run the SELECT and FROM first, check the columns, then add the WHERE conditions one at a time and confirm the row count after each one. When a number looks wrong, you will know exactly which condition caused it.

AI shortcut: Paste your table structure into ChatGPT or Claude and describe what you need in plain language: "I have a table orders(order_id, customer, state, order_date, amount) in PostgreSQL. Write a query that returns Texas and Georgia orders between 100 and 1000 dollars from the last 30 days, sorted by date, and explain each clause." Then run it and compare the result with what you expected; that is how you learn instead of just copying.

Beginner mistakes to avoid

  • Double quotes for text. In standard SQL, text values use single quotes ('FL'). Double quotes are for column or table names in many databases.
  • Forgetting the semicolon when running several statements in a row.
  • Comparing dates as text in the wrong format. Use ISO format (YYYY-MM-DD) to stay safe across databases.
  • Missing parentheses when combining AND and OR.
  • Assuming row order. Without ORDER BY, the database may return rows in any order.
  • Running SELECT * on huge tables. On a production database with millions of rows, always add a WHERE filter or a row limit while you explore, so you don't slow down the system for everyone else.

Next steps

Practice these three clauses on a real dataset until you can write them without looking. Then move on to combining tables with SQL JOINs and summarizing data with GROUP BY and aggregate functions. Once those feel comfortable, try a few SQL practice projects to build a portfolio.

Watch: video lessons

SQL Tutorial for Beginners: Database, JOIN, WHERE, GROUP BY, HAVING, ORDER BY, LIKE, IN, BETWEENby Coupler․io Academy · Watch on YouTube ↗
Cómo SELECCIONAR y FILTRAR datos en SQLby Rafa Gonzalez Gouveia · Watch on YouTube ↗Video in Spanish.

Frequently asked questions

Is SQL hard to learn for beginners?

The basics are approachable because the syntax reads close to English. Most people can write useful SELECT, WHERE and ORDER BY queries after a few practice sessions.

What is the correct order of SQL clauses?

Write them as SELECT, FROM, WHERE, ORDER BY. The database actually evaluates FROM and WHERE before SELECT, and ORDER BY last.

What is the difference between LIMIT and TOP?

Both return only the first rows of a result. LIMIT is used in PostgreSQL, MySQL and SQLite, while SQL Server uses TOP right after SELECT.

Which database should I use to practice SQL?

SQLite or PostgreSQL are good free options for practice. The basic clauses in this guide work the same way in almost every relational database.

Learning with the Academy?
Mark this lesson complete to track your rank progress.
Take the quiz