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 returns the constant value 1 for every row that the FROM and WHERE clauses produce. The 1 is not a column name and it does not reference the first column. It is a literal constant expression, and the database evaluates it once per qualifying row. The pattern is most commonly used inside EXISTS subqueries where the only question being asked is whether any matching rows exist at all.
What the Query Actually Returns
Consider a users table with four rows:
The result set contains four rows, each with a single unnamed column whose value is 1:
The database still performs the full FROM processing. It reads rows, applies any WHERE filters, and honors JOIN conditions. The only difference from a normal SELECT is that the projection is a constant instead of a column reference.
You can use any constant expression. SELECT 42 FROM users, SELECT 'yes' FROM users, and SELECT NULL FROM users all behave the same way. The number 1 is simply the convention.
The Primary Use Case: EXISTS Subqueries
The most important context for SELECT 1 is inside an EXISTS check:
The EXISTS operator does not inspect the values returned by the subquery. It only checks whether the subquery produces at least one row. That is why the projection does not matter. SELECT 1, SELECT *, and SELECT e.id all produce identical results inside EXISTS.
Writing SELECT 1 is a convention that signals intent to the reader: this subquery is purely an existence check, not a data retrieval operation.
EXISTS vs COUNT for Existence Checks
A common alternative to EXISTS is using COUNT(*) > 0. Both answer the same question, but they do different amounts of work.
The EXISTS version can short-circuit. Once the database finds a single qualifying row, it stops scanning. The COUNT(*) version must evaluate every qualifying row to produce the count, even though you only care whether the count is positive.
| Approach | Scans All Matching Rows | Short-Circuits | Intent |
EXISTS (SELECT 1 ...) | No | Yes | Existence check |
COUNT(*) > 0 | Yes | No | Counting (repurposed) |
SELECT 1 FROM ... LIMIT 1 | No | Yes | Existence check (alternative) |
In most modern query optimizers, the performance difference is negligible for small result sets. For large tables with many matching rows, EXISTS can be significantly faster.
SELECT 1 in Other Contexts
Health Checks and Connectivity Tests
A bare SELECT 1 without a FROM clause is used as a database connectivity test:
This query does not touch any table. It simply asks the database to return a constant. Connection pools and health check endpoints use this pattern because it exercises the connection with minimal overhead.
Some databases use variations. Oracle requires SELECT 1 FROM DUAL because Oracle does not support SELECT without a FROM clause. MySQL, PostgreSQL, SQL Server, and SQLite all support the bare SELECT 1.
Conditional Logic with CASE
SELECT 1 also appears in CASE expressions and IF checks within stored procedures:
INSERT with Existence Guard
A common pattern uses SELECT 1 in WHERE NOT EXISTS to prevent duplicate inserts:
This inserts the row only if no matching subscription already exists. The SELECT 1 inside the subquery is again an existence check.
What the Optimizer Actually Does
People sometimes believe that SELECT 1 is a performance optimization over SELECT * inside an EXISTS subquery. In practice, modern query optimizers (PostgreSQL, MySQL, SQL Server, Oracle) recognize EXISTS subqueries and optimize them identically regardless of the projection.
You can verify this with an execution plan:
Both plans will show the same operations. The optimizer knows that EXISTS only needs row existence, so it does not materialize columns in either case.
The real performance insight is not SELECT 1 vs SELECT *. It is EXISTS vs COUNT(*) > 0, where the optimizer's ability to short-circuit makes a measurable difference on large result sets.
SELECT 1 vs SELECT * vs SELECT column
| Expression | Inside EXISTS | As Standalone Query | Readability |
SELECT 1 | Identical performance | Returns constant per row | Clearly signals existence check |
SELECT * | Identical performance | Returns all columns | Ambiguous intent inside EXISTS |
SELECT e.id | Identical performance | Returns one column | Slightly misleading inside EXISTS |
Inside EXISTS, all three are equivalent. Outside EXISTS, they behave differently because the projection actually matters for the result set.
Common Pitfalls
Thinking 1 refers to the first column in the table is the most common misunderstanding. SQL column indexing in the SELECT list uses names, not positional numbers. The 1 is a literal integer value.
Assuming SELECT 1 has unique performance benefits is misleading. The performance advantage comes from EXISTS short-circuiting, not from the choice of projection.
Forgetting that SELECT 1 FROM table still returns one row per matching source row can produce unexpected result sizes. If the table has a million rows, the query returns a million rows each containing 1.
Using COUNT(*) when the real need is existence checking is a missed optimization. Use EXISTS for yes-or-no questions and COUNT(*) only when you need the actual count.
Treating SELECT 1 as mysterious or special syntax obscures what is a straightforward constant expression. Any valid SQL expression can appear in the SELECT list, and 1 is simply the conventional choice for existence checks.
Summary
SELECT 1 FROM tablereturns the literal value1for every row the query produces.- The
1is a constant expression, not a column reference or positional index. - The pattern is most common inside
EXISTSsubqueries, where only row existence matters. - '
EXISTSshort-circuits after finding one row, making it more efficient thanCOUNT(*) > 0for existence checks.' - A bare
SELECT 1(noFROM) is the standard database health check query. - Modern optimizers treat
SELECT 1,SELECT *, andSELECT columnidentically insideEXISTS.

