Skip to content
Quantoros

What does SELECT do and why shouldn't you use it in production?

SQLLevel: FoundationFundamentals (Easy)

What does SELECT * do and why shouldn't you use it in production?

Hints
  • Define one output row and the source-table keys.
  • Check duplicates, NULLs and the order of filtering and aggregation.

Answer

SELECT * returns every column in the table. You shouldn't use it in production for a few reasons:

  • You pull more data than you need, which wastes network and memory.
  • If the table schema changes (columns added or reordered), your application might break in unexpected ways.
  • The query optimizer can't as easily use covering indexes when you request all columns.
-- Bad in production
SELECT * FROM orders;

-- Better
SELECT order_id, customer_id, total_amount, created_at FROM orders;

Common wrong answer: People say "it's slower" without being able to explain why. The real answer is specificity, predictability, and network cost.

Source and licence: SQL Interview Questions — Arda Kocadoru · MIT

Related questions