🗄️ SQL examples

SELECT Examples in SQL

Select columns and build simple result sets. This page gives you the syntax, five practical examples, common mistakes, and copy-ready SQL you can adapt.

Updated 2026-06-125 practical examplesCopy-ready SQL

What SELECT does

Select columns and build simple result sets. SQL syntax can vary by database, but the pattern below is a useful starting point for reports and analysis.

Syntax or pattern

SELECT column1, column2 FROM table_name;
✍️

5 practical examples

1

Select customer names

Return only the columns needed for a customer list.

SELECT customer_id, first_name, last_name, email FROM customers;

Selecting fewer columns keeps the result easier to read and often faster to export.

2

Select order totals

Show order ID, date and amount for reporting.

SELECT order_id, order_date, total_amount FROM orders;

This is a common starting point for sales reporting queries.

3

Rename a calculated column

Create a friendly column name for a calculation.

SELECT order_id, quantity * unit_price AS line_total FROM order_items;

Aliases make calculated fields readable in reports.

4

Select unique product categories

List categories from a product table.

SELECT DISTINCT category FROM products;

DISTINCT removes repeated category names.

5

Select with a simple expression

Calculate tax or margin in the result.

SELECT product_name, price, price * 0.10 AS estimated_tax FROM products;

Expressions help create quick analysis columns without changing the source table.

Common mistakes to avoid

  • Forgetting that SQL dialects vary across PostgreSQL, SQL Server, MySQL, BigQuery and SQLite.
  • Using SELECT * in production reports when only a few columns are needed.
  • Not checking join keys, duplicate rows or NULL values before trusting results.

FAQ

Will this SQL work in every database?

The idea is portable, but function names and date syntax may vary. Check your database dialect if a function is not recognized.

Should I use this in a report query?

Yes, if the pattern matches the business question and you have checked filters, joins and row counts.

Why does my result have too many rows?

The most common reasons are duplicate join keys, missing filters or grouping at the wrong level of detail.

💡 Useful resources

Here are some ideas for you

Optional resources that may help if you are learning SQL, building reports, writing queries or improving your data workflow.

  • 📘
    SQL books for beginners

    Practice query patterns with structured examples and exercises.

    See ideas
  • 🧱
    Database design books

    Understand tables, keys, relationships and why joins behave the way they do.

    See ideas
  • ⌨️
    Mechanical keyboards

    Useful if you write queries, code and documentation for long work sessions.

    See ideas
  • 🖥️
    External monitors

    View query editor, result grid and documentation side by side.

    See ideas
  • 📒
    Developer notebooks

    Sketch table relationships, query logic and report ideas before coding.

    See ideas
  • 💡
    Desk lamps

    Keep your workspace comfortable while studying or debugging queries.

    See ideas

Some links in this section may be affiliate links. Choose only what is useful for your own work.