By: Jeremy Kadlec
Overview
If you are starting to learn the T-SQL language then starting with the SELECT statement makes a great deal of sense. The SELECT statement is used to access data and is generally the most used command in SQL Server. The main components of a SELECT statement are:
SELECT -- Column names FROM -- Table or View name WHERE -- Filter criteria GROUP BY -- Logic to roll-up records HAVING -- Criteria for GROUP BY logic ORDER BY – Sort data either ASC (ascending) or DESC (descending) by column name or position
SELECT can be combine with other statements to do the following:
- JOIN - JOINing data from multiple tables to build a single result set
- Add Records - INSERT with a SELECT statement to add records into an existing table
- Add Records - SELECT...INTO statement to create a new table based on the column list specification and enter records into the new table
- Combine Results - UNION or UNION ALL command to have multiple set of logic returned in a single result set
- Improve Performance - Include an index hint to force a particular lock level or index usage for the query
You can either use the outline on the top left of this tutorial or click on the arrows below to scroll through each of these topics in this tutorial
Additional Information
- SQL Server Join Example
- SQL Server JOIN Tables Tips
- SQL Server INSERT Tutorial
- INSERT with SELECT
- SELECT INTO
- UNION vs. UNION ALL in SQL Server
- Using Hints To Test SQL Server Indexes
Last Update: 6/18/2020