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.
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.
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', '[email protected]', 'New York'),
('John', 'Smith', '[email protected]', 'Chicago'),
('Alice', 'Johnson', '[email protected]', 'Austin');
-- Fetch only the columns needed by the UI
SELECT first_name, email, city
FROM demo_customers;
| first_name | city | |
|---|---|---|
| Jane | [email protected] | New York |
| John | [email protected] | Chicago |
| Alice | [email protected] | Austin |
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.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.AS: Use aliases like SELECT email AS contact_email to match your frontend JSON schema cleanly without extra mapping code.SELECT with WHERE and LIMIT so your backend only reads the exact rows needed for the current page or job.SELECT modify data inside the table?No, SELECT is a read-only query that fetches a result set without changing any stored rows.
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.
SELECT without a FROM clause in MySQL?Yes, expressions like SELECT 1 + 1; or SELECT VERSION(); run without referencing a table.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Experiment with the code from this lesson in our interactive playground.