Skip to main content

How do you select only specific columns?

To select only specific columns, list the names of the columns you need in the SELECT command, separated by commas.

Syntax:

sql
SELECT Column1, Column2, ... FROM Table_Name WHERE Condition;

Example:

sql
SELECT Name, Age FROM Employees WHERE DepartmentID = 101;

What this query does

  1. Pulls only the Name and Age columns from the Employees table.
  2. Filters records by the condition DepartmentID = 101.

Notes:

  • Any number of columns can be selected, even just one.
  • If every column is needed, SELECT * is used, and if only some, they're listed explicitly.

Put simply, this kind of query lets you get only the data you need, without cluttering the result with unnecessary columns.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.