What does it mean SELECT 1 FROM table?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
SELECT 1 FROM table means: return one literal value for every row the FROM clause produces. The 1 is not a column name, and it is not asking the database to look up a field called 1. It is simply a constant expression.
That is why the query is common in existence checks and subqueries. The point is often not the value 1 itself, but the fact that at least one row exists.
What The Query Actually Returns
Suppose you have a table named users with three rows. This query:
returns three rows, each containing the value 1:
The database still scans rows according to the FROM and WHERE clauses. The difference is that the selected expression is a constant instead of a column.
Why It Appears In EXISTS
The most common use is inside an EXISTS subquery:
Here, SELECT 1 is just a compact way to say "I only care whether a matching row exists." The subquery does not need employee names or salaries. It only needs to prove that at least one employee row matches.
In that context, SELECT 1, SELECT *, and SELECT e.id are usually equivalent in meaning because EXISTS cares about row existence, not returned column values.
It Is Not A Special Performance Trick By Itself
People sometimes assume SELECT 1 is magically faster than selecting a real column. In many databases, that is not the important distinction. The optimizer usually understands that an EXISTS subquery stops when it finds a qualifying row, regardless of whether the projection is 1 or a column.
So the main advantage of SELECT 1 is clarity. It tells readers, "this subquery is about existence, not data retrieval."
Compare It With COUNT(*)
Developers sometimes use COUNT(*) > 0 to answer an existence question. That works, but it can do more work than necessary because counting means evaluating all qualifying rows.
If you only need a yes-or-no answer, EXISTS is often the better expression of intent:
The second version communicates the real question directly.
Why Not SELECT *
Inside an EXISTS subquery, many teams prefer SELECT 1 simply because it makes intent obvious to human readers. The database usually cares about row existence, but the constant tells other developers that the subquery is not trying to project useful data.
Common Pitfalls
- Thinking
1refers to the first column in the table. - Assuming
SELECT 1always has unique performance benefits outside its query context. - Forgetting that
SELECT 1 FROM tablestill returns one row per matching source row. - Using
COUNT(*)when the real need is only to know whether any row exists. - Treating
SELECT 1as mysterious syntax instead of as a constant expression.
Summary
- '
SELECT 1 FROM tableselects a constant value for each row produced by the query.' - The
1is a literal, not a column reference. - The pattern is most common inside
EXISTSsubqueries. - Its main value is clarity of intent, not magic speed by itself.
- Use
EXISTSwhen the real question is whether matching rows exist at all.

