What does SELECT 1 FROM table mean in SQL?
Codemia Knowledge Hub ·
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 does not refer to the first column; it is a literal constant evaluated once per qualifying row. It is most often used inside EXISTS subqueries, where the only question is whether any matching rows exist.
What the query returns
Given a users table with four rows:
The result has four rows, each with a single unnamed column whose value is 1:
The database still does all the FROM processing: it reads rows, applies WHERE filters, and honors JOIN conditions. Only the projection differs. So if the table has a million rows, you get a million rows of 1.
Any constant works. SELECT 42 FROM users, SELECT 'yes' FROM users, and SELECT NULL FROM users behave the same way; 1 is just the convention.
SELECT 1 inside EXISTS subqueries
EXISTS does not inspect the values the subquery returns. It only checks whether the subquery produces at least one row, so the projection does not matter: SELECT 1, SELECT *, and SELECT e.id give identical results. Writing SELECT 1 tells the reader the subquery is purely an existence check.
EXISTS versus COUNT(*) > 0
Both answer "is there at least one row?", but they do different amounts of work:
EXISTS can short-circuit: once one qualifying row is found, scanning stops. COUNT(*) must evaluate every qualifying row. Use EXISTS for yes-or-no questions and COUNT(*) only when you need the count.
| 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) |
With most modern query optimizers, the difference is negligible for small result sets. For large tables with many matching rows, EXISTS can be significantly faster.
Other places SELECT 1 appears
Health checks and connectivity tests
A bare SELECT 1 with no FROM touches no table and just returns a constant. Connection pools and health check endpoints use it to exercise the connection with minimal overhead.
Oracle releases before 23ai require SELECT 1 FROM DUAL because they do not support SELECT without a FROM clause; Oracle Database 23ai accepts the bare form. MySQL, PostgreSQL, SQL Server, and SQLite all accept the bare SELECT 1.
Conditional logic in stored procedures
Guarding an INSERT against duplicates
The row is inserted only if no matching subscription exists.
Is SELECT 1 faster than SELECT * inside EXISTS?
No. Modern optimizers (PostgreSQL, MySQL, SQL Server, Oracle) recognize EXISTS subqueries and optimize them identically regardless of the projection. You can confirm with execution plans:
Both plans show the same operations, because the optimizer does not materialize columns for an existence check. The performance difference that actually matters is EXISTS versus COUNT(*) > 0.
| 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 |
Outside EXISTS, the three differ because the projection determines the result set.
Does the 1 refer to the first column?
No. This is the most common misunderstanding. Columns in the SELECT list are referenced by name, not position, and the 1 is a literal integer. There is nothing special about the syntax: any valid SQL expression can appear in the SELECT list.
Related reading
- What does it mean to hydrate an object?
- What does it mean when MySQL is in the state Sending data?
- What does mysql error 1025 HY000 Error on rename of './foo' errorno 150 mean?
- What does ON UPDATE RESTRICT do?
- What does it mean when it is stipulated that extra allowed space is O1?
- What does Java option -Xmx stand for?
- What does SQL clause GROUP BY 1 mean?
- What does Table does not support optimize, doing recreate analyze instead mean?
System design interview problems on this topic
- Design a Distributed OLTP Database: solution and walkthrough
- Design a Wide Column Database: solution and walkthrough
- Design a Key Value Store: solution and walkthrough
- Design a Web Cache: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.