Yes, SELECT is a clause in SQL — specifically, it is the first and most important clause in a SELECT statement, which is used to query data from a database. In SQL grammar, a clause is a distinct logical component of a statement, and SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, and LIMIT are all clauses that work together to form a complete query.
What Exactly Is a Clause in SQL?
In SQL, a clause is a named part of a statement that performs a specific function. Think of a statement as a full sentence and a clause as a phrase within it. The SELECT clause specifies which columns you want to retrieve, the FROM clause specifies the table(s) you’re querying, and the WHERE clause filters rows. Each clause has a defined syntax and order of operation, and together they form a valid SQL query.
For example, in the query:
SELECT first_name, last_name
FROM employees
WHERE department = 'Sales';
There are three clauses: SELECT, FROM, and WHERE. The SELECT clause is mandatory in a SELECT statement — you cannot query without it. The other clauses are optional depending on what you need.
How the SELECT Clause Works
The SELECT clause does two things: it determines which columns appear in the result set, and it can also compute new values using expressions, functions, or operators. You can list column names separated by commas, use an asterisk (*) to select all columns, or use expressions like SELECT price * quantity AS total.
Here’s a breakdown of what you can put in a SELECT clause:
- Column names:
SELECT name, agereturns those columns. - Asterisk:
SELECT *returns every column from the table. - Expressions:
SELECT price * 1.1 AS price_with_taxcalculates a new value. - Functions:
SELECT COUNT(*)returns a count of rows. - Literals:
SELECT 'Hello' AS greetingreturns a constant.
The SELECT clause is evaluated after the FROM and WHERE clauses in terms of logical processing order, even though it appears first in the written query. The database first determines which rows to use, then which columns to project.
Why People Confuse SELECT with a Statement
Many beginners use the word “SELECT” to mean the entire query, as in “I wrote a SELECT to get the data.” That’s common shorthand, but technically the statement is the whole thing, and SELECT is just one clause within it. The confusion arises because SELECT is the first word and the most visible part of a query.
To be precise: a SQL statement is a complete command like SELECT ... FROM ... WHERE ..., INSERT INTO ..., or UPDATE .... A clause is a component of a statement. So SELECT is a clause, and the full query is a statement. This distinction matters when reading SQL documentation or writing complex queries with subqueries.
All the Main Clauses in a SELECT Statement
Here are the core clauses that can appear in a SELECT statement, in the order they must be written:
SELECT— specifies columns and expressions.FROM— names the table(s) to query.WHERE— filters rows based on conditions.GROUP BY— groups rows that have the same values in specified columns.HAVING— filters groups after aggregation.ORDER BY— sorts the result set.LIMIT(orFETCHin some databases) — restricts the number of rows returned.
Not all databases support every clause in the same way. For example, LIMIT is used in MySQL, PostgreSQL, and SQLite, while SQL Server uses TOP and Oracle uses FETCH FIRST. But the SELECT clause itself is universal.
Common Misconceptions About SELECT
One common myth is that SELECT is a keyword, not a clause. In fact, it is both — a keyword is a reserved word in the SQL language, and a clause is a syntactic unit. SELECT is a reserved keyword that begins the SELECT clause. Another misconception is that you can write SELECT without FROM in all databases. While some databases (like Oracle and PostgreSQL) allow SELECT 1 without a table, others (like SQL Server) require a FROM clause unless you use a workaround like SELECT 1 (which works in SQL Server too, actually). But for querying actual data, FROM is essential.
Another point of confusion is the difference between SELECT and SELECT DISTINCT. The DISTINCT keyword is part of the SELECT clause, not a separate clause. It modifies the SELECT to remove duplicate rows from the result.
How to Write a Correct SELECT Clause
Writing a correct SELECT clause is straightforward, but there are a few rules to keep in mind:
- Always list columns in the order you want them to appear in the result.
- Use aliases (with
AS) to rename columns or expressions for readability. - If you’re using an aggregate function like
COUNTorSUM, you must useGROUP BYfor any non-aggregated columns. - Be careful with
SELECT *in production — it can return unnecessary columns and slow down performance.
For example, to get a list of departments with their employee counts:
SELECT department, COUNT(*) AS employee_count
FROM employees
GROUP BY department;
Here, the SELECT clause includes both a column (department) and an aggregate expression (COUNT(*)). The GROUP BY clause is required because department is not aggregated.
Frequently Asked Questions
Is SELECT a keyword or a clause?
It is both. SELECT is a reserved keyword in SQL, and it also forms the SELECT clause, which is the first part of a query. The keyword is the token you type; the clause is the grammatical structure it creates.
Can you have a SELECT statement without FROM?
Yes, in many databases you can write SELECT 1 or SELECT 'Hello' without a FROM clause. This is often used for testing or to return a single value. However, if you want to retrieve data from a table, FROM is required.
What is the difference between SELECT and SELECT DISTINCT?
SELECT returns all rows that match the query, including duplicates. SELECT DISTINCT removes duplicate rows from the result set, returning only unique combinations of the selected columns. It’s a modifier of the SELECT clause, not a separate clause.
Does the order of clauses matter in SQL?
Yes, the order is fixed by the SQL standard: SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT. Writing them out of order will cause a syntax error. However, the logical execution order is different — the database processes FROM, then WHERE, then GROUP BY, then HAVING, then SELECT, then ORDER BY, and finally LIMIT.
Is SELECT the only clause that can appear first?
In a SELECT statement, yes. But there are other types of statements like INSERT, UPDATE, and DELETE that start with their own keywords. In a subquery, SELECT also comes first. So while SELECT is the first clause of a query, it’s not the first clause of every SQL statement.
Can I use SELECT without specifying columns?
Yes, you can use SELECT * to get all columns, or SELECT with no column list if you’re selecting a constant (e.g., SELECT 1). But in a typical data retrieval, you specify at least one column or expression.
Related
- Excel Budget Report Template: How to Build One
- Excel Budget Calendar Template: How to Build One
- Excel Sum Showing Zero? Fixes That Work
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- Outlook Reading Pane: How to Change the View and LayoutTo change your Outlook reading pane, open the mail view and choose a position: in classic Outlook for…
- COUNTIF in Google Sheets: Syntax, Examples, and TipsIn Google Sheets, use COUNTIF(range, criterion) to count cells in a range that meet one condition. For example,…
- How to Make a Nice Poster in PowerPoint: A Practical GuideTo make a nice poster in PowerPoint, set the slide to the poster’s final dimensions, choose one clear…
- Project Timeline in Microsoft Excel: Build and Manage ItA project timeline in Microsoft Excel is a dated plan that shows when tasks start, when they finish,…
- Freeze a Line in Excel While Scrolling Rows and ColumnsTo keep a row or column visible while you scroll in Excel for Microsoft 365 on Windows, open…
- Freeze Panes in Excel: How to Keep Rows and Columns VisibleIn Excel for Microsoft 365 on Windows, use View > Freeze Panes to keep rows or columns visible…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.