Select all SQL columns except specified columns
How to select every column except one or more in SQL: Snowflake EXCLUDE, BigQuery EXCEPT, workarounds for other databases, and when an explicit list is safer.
Selecting every column except a few is a common need: dropping a large text column from an exploratory query, hiding an internal ID from an export, or avoiding a duplicate key after a join. Standard SQL has no syntax for this. SELECT * returns every column, and the only portable way to leave one out is to list the rest by name. Several analytical databases have added a shortcut, though, and Snowflake is one of the most frequently asked about. This review covers what those shortcuts do, where they work, and when an explicit column list is the better choice.
A note on evidence: no test results, version-specific measurements or vendor documentation excerpts were supplied for this article. The syntax below reflects documented behavior of each product as generally published, but the queries have not been run here. Confirm details against the documentation for the version you use.
Is an "all columns except" query suitable for your use?
For interactive analysis, notebooks and one-off exports, an exclusion clause is usually a good fit. It saves typing on wide tables and makes the intent clear: everything except these columns. On columnar warehouses, leaving out a large column can also reduce the amount of data read.
The decisive tradeoff is schema drift. An exclusion clause still expands at run time, so any column added to the table later is included automatically. That is convenient for exploration, but in production pipelines, application code, reports with a fixed layout, or anything feeding a downstream system, a new column can appear without anyone deciding it should. In those settings, an explicit column list is preferable because the output shape only changes when someone edits the query.
An explicit list is also the better choice when the query must run on more than one database engine, since exclusion syntax is not portable.
What the exclusion clause actually changes
An exclusion clause changes only the projection, meaning the list of columns the query returns. It does not alter, hide or delete anything in the stored table. The excluded columns are still present, still readable by anyone with access, and still available to other queries. It is a shorthand for writing out the remaining column names.
The keyword can be confusing because "EXCEPT" means two different things in SQL. As a set operator between two queries (SELECT ... EXCEPT SELECT ...), it removes rows that appear in the second result. As a modifier attached to the star (SELECT * EXCEPT (...)), it removes columns. The two are unrelated, and a search for "SQL except" will return results for both.
Snowflake: SELECT * EXCLUDE
Snowflake uses the keyword EXCLUDE after the star. A single column can be named directly, and several columns go in parentheses.
-- One column
SELECT * EXCLUDE employee_id
FROM employees;
-- Several columns
SELECT * EXCLUDE (employee_id, salary)
FROM employees;
Snowflake also accepts EXCLUDE on a table-qualified star, which helps in joins where the same key column appears on both sides. Related star modifiers, RENAME and REPLACE, let you rename or recompute columns in the same expansion.
SELECT e.* EXCLUDE (department_id),
d.department_name
FROM employees e
JOIN departments d
ON e.department_id = d.department_id;
Other engines with a built-in clause
| Engine | Syntax | Notes |
| Snowflake | SELECT * EXCLUDE (col1, col2) | Parentheses optional for a single column |
| BigQuery | SELECT * EXCEPT (col1, col2) | Parentheses required |
| Databricks SQL | SELECT * EXCEPT (col1, col2) | Check runtime version for support |
| DuckDB | SELECT * EXCLUDE (col1, col2) | Same keyword as Snowflake |
| ClickHouse | SELECT * EXCEPT (col1, col2) | Column modifier, separate from set EXCEPT |
| PostgreSQL, MySQL, SQL Server, Oracle, SQLite | None | Use an explicit list or one of the workarounds below |
Naming a column that does not exist is generally treated as an error rather than silently ignored, but this was not verified for every engine listed. Test it in your environment if your queries depend on it.
Workarounds where no clause exists
In databases without exclusion syntax, the usual approach is to generate the column list from the catalog once, paste it into the query, and maintain it from there. In PostgreSQL:
SELECT string_agg(quote_ident(column_name), ', '
ORDER BY ordinal_position)
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'employees'
AND column_name NOT IN ('ssn', 'salary');
The MySQL equivalent uses GROUP_CONCAT. Its output is truncated at the group_concat_max_len setting, so a very wide table may need that value raised for the session.
SELECT GROUP_CONCAT(column_name ORDER BY ordinal_position SEPARATOR ', ')
FROM information_schema.columns
WHERE table_schema = DATABASE()
AND table_name = 'employees'
AND column_name NOT IN ('ssn', 'salary');
- Other options:
- Create a view that lists the wanted columns, and query the view with SELECT *.
- Build the statement with dynamic SQL from the catalog query. This adapts to schema changes but is harder to read and review.
- On engines that support invisible columns, such as Oracle and recent MySQL 8.0 releases, mark a column invisible so SELECT * skips it. This changes the table definition for every user, not just one query.
Will the query stay usable when shared or reused?
Portability is the main limit. A query using EXCLUDE copied from Snowflake into BigQuery fails because BigQuery spells it EXCEPT, and it fails on PostgreSQL or SQL Server because neither has the feature. If a query is shared across teams on different platforms, or kept in a library of reusable snippets, write the explicit column list or note which dialect the query targets.
Views need care. Some engines, PostgreSQL among them, expand a star into a fixed column list when the view is created, so later table changes do not appear in the view. Others validate the view when it is queried and may raise an error if the underlying columns have changed. Whether a star with exclusions inside a view picks up new columns depends on the engine, and this was not tested here.
Excluding a column is not an access control. Leaving a sensitive column such as a national ID or salary out of a query keeps it out of that result, but anyone who can run SELECT * against the table can still read it. If the goal is to protect data, use column-level privileges, masking policies or a restricted view granted in place of the base table.
Bottom line
Use Snowflake's EXCLUDE, or BigQuery's and others' EXCEPT, for exploration and quick exports on wide tables, where the shorter query and reduced scanning outweigh the risk of new columns appearing unexpectedly. Switch to an explicit column list for production pipelines, cross-database code and fixed-format outputs. Use permissions or masking, not query syntax, to keep columns away from people who should not see them.