🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
💼 Servicesℹ️ About✉️ ContactView Pricing Plansfrom $10

SELECT Statement

SQL FundamentalsDML🟢 Free Lesson

SQL Fundamentals

The SELECT Statement

The foundation of every SQL query — retrieve exactly the data you need from your database.

  • Targeted Retrieval — select specific columns instead of entire tables
  • Computed Columns — calculate values on the fly with expressions
  • Clean Output — alias columns for readable, report-ready results

SELECT is how you ask your database questions.

What is SELECT?

SQL Query Execution Order1. FROM2. WHERE3. GROUP BY4. HAVING5. SELECT6. ORDER BY7. LIMIT/OFFSETFROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY → LIMIT
SELECT column1, column2
FROM table_name;
ComponentDescriptionRequired
SELECTColumns to retrieveYes
column1, column2Specific columns or * for allYes
FROMTable to queryYes
table_nameSource tableYes

Select All Columns

SELECT * FROM customers;
idfirst_namelast_nameemailcity
1AliceJohnsonalice@email.comNew York
2BobSmithbob@email.comLos Angeles
3CarolWilliamscarol@email.comChicago

Select Specific Columns

SELECT first_name, last_name, email
FROM customers;
first_namelast_nameemail
AliceJohnsonalice@email.com
BobSmithbob@email.com
-- SLOW: Returns all columns
SELECT * FROM customers WHERE city = 'New York';

-- FAST: Returns only needed columns
SELECT first_name, last_name, email
FROM customers
WHERE city = 'New York';

Expressions in SELECT

SELECT
    name,
    price,
    price * 1.08 AS price_with_tax,
    price * stock AS inventory_value,
    ROUND(price * 0.9, 2) AS discounted
FROM products;
namepriceprice_with_taxinventory_valuediscounted
Mouse29.9932.394498.5026.99
Keyboard89.9997.196749.2580.99

Common Functions

-- String functions
SELECT
    UPPER(first_name) AS upper_name,
    LOWER(last_name) AS lower_name,
    LENGTH(email) AS email_length,
    CONCAT(first_name, ' ', last_name) AS full_name
FROM customers;

-- Math functions
SELECT
    price,
    ROUND(price, 0) AS rounded,
    CEIL(price) AS ceiling,
    FLOOR(price) AS floor_price,
    ABS(-price) AS absolute
FROM products;

-- Date functions
SELECT
    hire_date,
    YEAR(hire_date) AS hire_year,
    MONTH(hire_date) AS hire_month,
    DATEDIFF(CURRENT_DATE, hire_date) AS days_employed
FROM employees;

Column Aliases

SELECT
    first_name AS "First Name",
    last_name AS "Last Name",
    salary AS annual_salary,
    salary * 12 AS monthly_salary
FROM employees;
First NameLast Nameannual_salarymonthly_salary
AliceJohnson750006250
BobSmith620005166.67

SELECT Without a Table

-- Perform calculations without any table
SELECT 1 + 1 AS result;                    -- 2
SELECT CURRENT_DATE AS today;              -- 2024-01-15
SELECT 'Hello, World!' AS greeting;        -- Hello, World!
SELECT RANDOM();                           -- Random number

SQL Execution Order

StepClauseWhat It Does
1FROMIdentify source tables
2WHEREFilter rows
3GROUP BYGroup rows
4HAVINGFilter groups
5SELECTChoose columns
6ORDER BYSort results
7LIMITRestrict row count
-- What you write:
SELECT first_name, salary
FROM employees
WHERE department = 'Engineering'
ORDER BY salary DESC
LIMIT 5;

-- How it executes:
-- 1. FROM employees        → All employee rows
-- 2. WHERE department='Engineering' → Only engineers
-- 3. SELECT first_name, salary → Just those two columns
-- 4. ORDER BY salary DESC  → Highest salary first
-- 5. LIMIT 5               → Top 5 only

Performance Tips

TipBad ExampleGood ExampleImpact
Use specific columnsSELECT *SELECT name, priceFaster
Add WHERE clauseNo filterWHERE id > 1000Fewer rows
Use LIMITUnlimited resultsLIMIT 100Smaller result

Common Mistakes

-- BAD: SELECT * in production
SELECT * FROM customers;

-- GOOD: Specific columns
SELECT id, first_name, last_name, email FROM customers;

-- BAD: Missing WHERE clause
SELECT * FROM customers;

-- GOOD: Filter with WHERE
SELECT * FROM customers WHERE is_active = TRUE;

-- BAD: No LIMIT for large tables
SELECT * FROM logs;

-- GOOD: Limit results
SELECT * FROM logs ORDER BY created_at DESC LIMIT 100;

Practice Exercises

Exercise 1: Write a query to select name and price from products, and calculate a 10% discount as discounted_price.

SELECT
    name,
    price,
    price * 0.9 AS discounted_price
FROM products;

Exercise 2: Select all employees with their annual salary (salary * 12).

SELECT
    first_name,
    last_name,
    salary,
    salary * 12 AS annual_salary
FROM employees;

Exercise 3: Select customers with formatted names and email length.

SELECT
    UPPER(first_name) AS first_name,
    UPPER(last_name) AS last_name,
    CONCAT(first_name, ' ', last_name) AS full_name,
    LENGTH(email) AS email_length
FROM customers;

Extended Learning: Beyond the Basics

Key Concepts Summary

This lesson covers fundamental concepts that serve as building blocks for more advanced topics. Master these basics before moving to intermediate and advanced material.

Prerequisite Knowledge

Before studying this topic in depth, ensure you understand:

  • Basic definitions and terminology
  • Core formulas and their derivations
  • Common applications in real-world scenarios
  • Typical pitfalls and misconceptions

Step-by-Step Walkthrough

Let us work through a complete example to solidify understanding:

Step 1: Identify the problem type. Determine which category this problem falls into and which approach is most appropriate.

Step 2: Apply the relevant formula. Substitute known values into the appropriate equation, paying attention to units and constraints.

Step 3: Simplify and solve. Work through the algebra step by step, checking each intermediate result.

Step 4: Verify the answer. Check that the solution satisfies the original conditions and makes logical sense.

Common Mistakes to Avoid

  1. Misidentifying the problem type — Always start by categorizing the problem
  2. Incorrect formula application — Verify the formula applies to your specific case
  3. Unit errors — Always check units are consistent throughout
  4. Sign errors — Pay careful attention to positive and negative values
  5. Rounding too early — Keep full precision until the final answer
  6. Forgetting constraints — Check that solutions satisfy all given conditions

Real-World Applications

Understanding this concept is essential for:

  • Advanced problem solving in examinations
  • Building intuition for more complex topics
  • Developing analytical thinking skills
  • Applying mathematical reasoning to practical situations

Practice Exercises

  1. Basic: Solve 5 problems of increasing difficulty using the core concept.
  2. Intermediate: Apply the concept to word problems with multiple steps.
  3. Advanced: Combine this concept with 2-3 other topics in a comprehensive problem.
  4. Challenge: Create your own problem that requires this concept plus additional knowledge.

Interview and Exam Tips

  • Common question patterns: Identify which exam or interview formats test this topic
  • Time management: Practice completing problems within time constraints
  • Common traps: Know the typical mistakes examiners set as distractors
  • Verification strategy: Develop a quick method to check your answer

Related Topics

Quick Reference Card

ConceptFormula/RuleKey InsightCommon Use
Core DefinitionSee main textUnderstand the intuitionFoundation for all applications
Key FormulaSee main textMemorize the derivationDirect problem solving
Special CaseSee main textRecognize when it appliesSimplifies complex problems
Edge CaseSee main textKnow the limitationsAvoids errors

Further Reading

For students who want to go deeper:

  • Standard textbooks on the subject
  • Research papers applying this concept
  • Online courses with video explanations
  • Practice problem collections with detailed solutions
CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-11-14

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert SQL Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement