Select specific columns from a SQL table

How to select specific columns in SQL and PostgreSQL: syntax, what changes and what doesn't, explicit lists vs SELECT *, and keeping results usable when exported.

To select specific columns from a SQL table, you name the columns you want in the SELECT list instead of using an asterisk. The database returns a result set with only those columns, and the table itself is not changed. This overview covers the syntax, PostgreSQL details, how this differs from other things people call "selecting columns", and what to check when you copy or export the result.

The short answer: is an explicit column list the right choice?

For most saved queries, reports and application code, list the columns explicitly. The main benefit is predictable output. You get the same columns in the same order even if someone later adds, removes or reorders columns in the table. The decisive tradeoff is maintenance: you must know the exact column names and update the query whenever you need more data. SELECT * is still reasonable for a quick look at an unfamiliar table, ideally with a LIMIT clause.

A plain-text export is the better hand-off in some cases. One is when the recipient has no database access. Another is when the data has to go into a tool that only reads delimited files. A third is when you need a fixed snapshot rather than a live query. If the data already exists only as a CSV file and you need a one-off subset of fields, a delimited-text column tool or a spreadsheet may be quicker than loading it into a database. Those tools vary in how well they handle quoted fields, so test them on awkward rows first.

Basic syntax for selecting columns

The general form is a comma-separated list of column names after SELECT, followed by the table name after FROM:

SELECT column1, column2
FROM table_name;

Selecting two columns from a customers table looks like this:

SELECT first_name, email
FROM customers;

Columns appear in the order you list them, not in the order they are defined in the table. The SELECT list can also contain expressions. You can rename any output column with AS. Filtering, sorting and limiting are added with WHERE, ORDER BY and LIMIT. CAST is the portable way to convert types; PostgreSQL also accepts its own :: shorthand.

SELECT first_name AS name,
       email,
       CAST(created_at AS DATE) AS signup_date
FROM customers
WHERE status = 'active'
ORDER BY created_at DESC
LIMIT 50;

What selecting columns actually changes

In relational terms, choosing columns is a projection. It is a read operation. Nothing is dropped, reordered or rewritten in the stored table, and other users see no difference. The only thing that changes is the shape of the result you receive. If you want that shape to persist, you have two options. CREATE VIEW saves the query under a name. A regular view stores the query, not a copy of the data. CREATE TABLE ... AS SELECT stores a snapshot copy that will not track later changes. Permanently removing a column requires ALTER TABLE ... DROP COLUMN. That is a separate and destructive operation, unrelated to SELECT.

Narrowing the column list can make distinct rows look identical. Two customers in the same city, for example, become two identical rows if you select only the city. SELECT keeps those duplicates. Add DISTINCT if you want unique combinations:

SELECT DISTINCT city, state
FROM customers;

"Select columns" can mean other things, too. Text editors offer column or box selection, which highlights a rectangular block of characters. Delimited-text tools pick fields out of CSV or tab-separated text. Both work on characters or fields in a text file. They do not know data types, and they only respect quoting rules if they were designed to. In this article, the phrase means choosing columns in a SQL query.

Selecting columns from a table in PostgreSQL

The syntax is the same in PostgreSQL. The main difference is how it treats identifiers. PostgreSQL folds unquoted identifiers to lowercase, so FirstName, firstname and FIRSTNAME all refer to a column named firstname. If a column was created with double quotes and mixed case or spaces, you must quote it the same way every time:

SELECT "FirstName", "Email Address"
FROM customers;

To find the exact column names, run \d customers in psql or query the information schema:

SELECT column_name, data_type
FROM information_schema.columns
WHERE table_schema = 'public'
  AND table_name = 'customers'
ORDER BY ordinal_position;

PostgreSQL has no syntax for "all columns except these". Some other engines offer an exclusion form of SELECT *, but it is not portable. In PostgreSQL, list the columns you want, or define a view with that list once and query the view.

Explicit column list vs SELECT *

Aspect | Explicit column list | SELECT *
Output stability | Fixed columns and order | Changes when the table definition changes
Data transferred | Only what you name | Every column, including large text or binary fields
Index use | In PostgreSQL, may allow an index-only scan when every selected column is in one index | Rarely allows an index-only scan
Effort | Requires knowing and maintaining names | Nothing to type or maintain
Best fit | Saved queries, reports, application code, exports | Quick exploration of unfamiliar tables

Will the result stay usable after copying or exporting?

Copying from a query tool's result grid depends on the tool. Some clients copy tab-separated text and some do not. Header rows may or may not be included. Values containing tabs or line breaks may or may not be escaped. This overview did not test any specific client. Check your client's documentation, or paste a small sample containing commas, tabs, line breaks and NULL values before relying on it.

In PostgreSQL, COPY with the CSV format gives you a more dependable delimited file. It quotes fields that contain the delimiter, a quote character or a newline. The psql \copy command runs on the client and writes the file to your own machine. A server-side COPY ... TO a file writes on the database server and needs elevated privileges.

\copy (SELECT first_name, email FROM customers WHERE status = 'active') TO 'active_customers.csv' WITH (FORMAT csv, HEADER)

A delimited export loses some meaning. Data types are gone, so every value becomes text. In PostgreSQL's CSV format, NULL is written as an unquoted empty field by default and an empty string is written as "". A spreadsheet or script reading the file may treat both the same way. Some spreadsheet applications also reformat values on import, such as dropping leading zeros or converting date-like strings. When the meaning of a value matters, check it in the destination, not only in the file.

For readability, keep the header row and use clear aliases so recipients know what each column holds. Wide results are hard to scan in plain text no matter which tool displays them. Selecting only the needed columns is often the simplest fix. This overview makes no claims about how particular screen readers or other assistive technologies present CSV files or result grids, because none were tested.

Selecting fewer columns also limits what you share, which helps when a table contains personal or sensitive fields. If you plan to paste results into an online converter or column tool, read its documented data-handling terms first. Its appearance or marketing language does not tell you how it stores or retains what you upload.

Limits of this overview

No subject-specific measurements, benchmarks or version-dated behavior were available for this article. The performance points above describe general mechanisms, not measured gains. Identifier rules, exclusion syntax and export commands differ between database engines, and copy behavior differs between client tools. Confirm the details in the documentation for the system you use.