How can I suppress column header output for a single SQL statement?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Suppressing column headers for one query is usually a client-tool problem, not a SQL language feature. SQL describes what data to return, while the client decides how to print it. That is why the right answer depends on whether you are using psql, mysql, sqlcmd, sqlite3, or some other shell.
Why SQL Itself Usually Does Not Control Headers
A SELECT statement returns a result set with column metadata. Whether those names appear in terminal output is decided by the client rendering the result.
So the question is really: how do I tell my SQL client to hide headers for just one command without changing the whole session permanently?
That is a formatting concern, not a query-logic concern.
Common Client-Specific Solutions
For PostgreSQL psql, use tuple-only mode for a single command.
For MySQL, -N or --skip-column-names removes headers.
For SQL Server sqlcmd, -h -1 suppresses headers.
For SQLite, turn headers off in the client session.
Scope the Change to One Command Block
The safest pattern is to make the formatting change local to the specific execution. For example, in psql you can bracket one query with output settings:
That keeps interactive defaults intact and prevents later commands from silently changing format.
Prefer Application-Level Formatting in Code
If the query is being executed from application code, suppressing headers is irrelevant because drivers return rows, not terminal tables. Format the result yourself.
This is more reliable than shell parsing because you control the output exactly.
Think About Machine Parsing, Not Just Headers
When a query feeds another script, column headers are only one part of the problem. You may also need to control:
- row-count footers
- delimiters
- quoting
- NULL rendering
- whitespace trimming
A command that hides headers but still prints decorative table borders is not actually machine-friendly.
That is why it is often better to pair header suppression with a stable output mode such as tuple-only, list, CSV, or delimiter-separated format.
For one-off shell pipelines, it is worth testing the exact command output with a sample query before wiring it into automation. That catches formatting surprises early.
Common Pitfalls
- Looking for a universal SQL clause to suppress headers when the feature belongs to the client.
- Disabling headers globally and forgetting to restore the setting.
- Parsing pretty-printed table output in automation scripts.
- Hiding headers but leaving row-count footers or formatting noise in place.
Summary
- Header suppression is usually controlled by the SQL client, not by SQL syntax itself.
- Use client-specific flags such as
-t,-N, or-h -1for one-off command output. - Keep formatting changes scoped to a single execution when possible.
- In application code, format rows directly instead of relying on shell output rules.
- For automation, consider the whole output format, not only the headers.

