Understanding Transact-SQL SELECT, FROM, and WHERE clauses
In this section, you will learn how to use the Transact-SQL SELECT, FROM, and WHERE clauses to retrieve the data you need from the SQL Server databases.
The SELECT statement
The SELECT statement is the most frequently used Transact-SQL statement. We use the SELECT statement for the following purposes:
- To query specific data from the selected database tables
- To assign a value to local variables
- To call a function
We often see SELECT statements within programming objects (such as views, stored procedures, functions, batches, and
common table expressions (CTEs)). We also use SELECT statements to run ad hoc queries, most often through an SSMS 2014 query window. The SELECT statement has several clauses, most of which are optional. The following is the general syntax of the SELECT statement:
SELECT [TOP(n)|TOP(n) PERCENT] [ALL|DISTINCT] select_list [INTO[[database.]owner.]table_name] FROM[[[database.]owner.]table_name|view_name|UDF] [WHERE...