Selecting Specific Columns
Instead of pulling back every column with
*, you can ask for exactly the columns you need, in exactly the order you want them to appear. This is the normal, day-to-day way a SELECT query is written.Naming columns explicitly
Select named columns
SQL
SELECT first_name, last_name, department, salary FROM employees;
The database returns exactly those four columns, and only those four — nothing more, nothing less.
Column order in the output
The order the columns appear in the result set is determined entirely by the order you list them after
SELECT, regardless of how they are physically ordered in the table definition. This query returns salary before first_name, even though the table itself might define the columns the other way around:Output order follows the SELECT list
SQL
SELECT salary, first_name, last_name FROM employees;
Computed / expression columns
A column in the
SELECT list does not have to be a raw table column — it can be an expression. The database evaluates the expression for every row and includes the result as a new column.A computed column
SQL
SELECT product_name,
price,
quantity,
price * quantity AS total
FROM order_items;Here
total is not stored anywhere — it is calculated on the fly, once per row, from the price and quantity columns of that row. Expression columns can mix arithmetic, string concatenation, function calls, and constants, and can combine several real columns together.Arithmetic — combining numeric columns, such as price times quantity, or a total minus a discount
String building — combining first and last name into a single display value
Function calls — applying a date or numeric function to a column before returning it
Constants — including a fixed literal value, useful for tagging rows from different queries in a UNION
Always list the columns you need in application code
Even when it is tempting to grab everything, naming your columns explicitly makes queries self-documenting, keeps the payload small, and means a schema change (a new column added elsewhere in the table) can never silently change what your application receives.