Why You Should Avoid SELECT * in Production Queries

Understand why explicitly selecting columns can make MySQL queries clearer, more predictable and easier to maintain.

ADVERTISEMENT

The asterisk in SELECT * tells MySQL to return every column from the selected table or tables. It is convenient while exploring data, but production queries often benefit from explicitly naming the required columns.

What SELECT * Does

SELECT *
FROM users
WHERE status = 'active';

This query returns all columns for matching rows. If the table contains columns that the application does not need, those values are still returned.

Prefer Explicit Columns

SELECT id, name, email
FROM users
WHERE status = 'active';

The second query clearly communicates which data the application expects. That makes it easier to read and maintain.

It Helps Keep Data Transfer Focused

Large tables may contain text, JSON or other wide columns. Returning only the required fields can reduce unnecessary data transfer between the database and application.

It Makes JOINs Clearer

SELECT
    c.id,
    c.name,
    o.order_date
FROM customers c
INNER JOIN orders o
    ON c.id = o.customer_id;

When SELECT * Is Fine

SELECT * can be perfectly reasonable for quick database exploration or a controlled administrative check. The goal is not to ban it everywhere, but to be intentional in application code.

Practical tip: Ask yourself, “Do I really need every column?” If not, list the columns you actually need.

Final Thoughts

Explicit SELECT lists are a small habit that can make SQL easier to understand and maintain, especially as applications and database schemas grow.