Lesson

MySQL SELECT Statement

10 min reading
Free Course

MySQL SELECT Statement: Querying Table Data

The MySQL SELECT statement reads and returns rows from one or more database tables. It is the most common SQL command you write when building APIs, reports, and admin dashboards.

Basic SELECT Syntax

List the exact columns you need after SELECT, followed by FROM and the table name:

SELECT column1, column2
FROM table_name;

Use an asterisk (SELECT *) only for quick ad-hoc inspection in a terminal. Explicit column lists keep application queries predictable even when future migrations add new columns.

Practical SQL Example

This script creates a demo_customers table, inserts three rows, and queries three specific columns.

CREATE TABLE demo_customers (
    id INT AUTO_INCREMENT PRIMARY KEY,
    first_name VARCHAR(50),
    last_name VARCHAR(50),
    email VARCHAR(100),
    city VARCHAR(50)
);

INSERT INTO demo_customers (first_name, last_name, email, city) VALUES
('Jane', 'Doe', 'jane@example.com', 'New York'),
('John', 'Smith', 'john@example.com', 'Chicago'),
('Alice', 'Johnson', 'alice@example.com', 'Austin');

-- Fetch only the columns needed by the UI
SELECT first_name, email, city
FROM demo_customers;
first_name email city
Jane jane@example.com New York
John john@example.com Chicago
Alice alice@example.com Austin

Common Mistakes and Best Practices

  • Avoid SELECT * in Production: Reading every column pulls large text blobs over the network and blocks covering index optimizations. Explicit column lists also prevent application bugs when future migrations add or reorder columns.
  • Expect Unordered Rows Without ORDER BY: MySQL makes no guarantee about row order unless you append an explicit ORDER BY clause. Never rely on insertion order for UI lists or paginated endpoints.
  • Rename Output Columns with AS: Use aliases like SELECT email AS contact_email to match your frontend JSON schema cleanly without extra mapping code.
  • Keep Queries Focused: Combine SELECT with WHERE and LIMIT so your backend only reads the exact rows needed for the current page or job.

Frequently Asked Questions

Does SELECT modify data inside the table?

No, SELECT is a read-only query that fetches a result set without changing any stored rows.

Why is SELECT * slower than listing column names?

SELECT * forces MySQL to read full table rows from disk instead of answering queries directly from smaller secondary indexes.

Can I use SELECT without a FROM clause in MySQL?

Yes, expressions like SELECT 1 + 1; or SELECT VERSION(); run without referencing a table.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Try it Yourself

Experiment with the code from this lesson in our interactive playground.

Open Playground
MySQL Topic Hub

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum