T-SQL Tutorials - TSQLTutorials.com

SELECT Statement


Introduction

The SELECT statement is used for retrieving data from a table. This SQL Statement begins with the keyword SELECT. The results from the SELECT query is called the 'Resultset'. The SELECT Statement has two basic parts:

  • SELECT
  • FROM
following the 'SELECT' keyword will be the columns to be selected
following the 'FROM' keyword will be the table to be selected from.

Beginning Example

This example will select the 'Name', 'Position' and 'Salary' columns' content from the 'Employees' table. Note: This example selects all of the records from the table. SELECT Name, Position, Salary
FROM Employees
Here is a sample resultset from the above SELECT query:

NamePositionSalary
Joe GrapeManager80000
John PlumSoftware Developer65000
Frank AppleSoftware Developer62000
Patty PineappleSoftware Developer60000
Judy PeachSoftware Developer50000
Jane OrangeProject Manager75000




Selecting ALL Columns - *

Previously we selected columns by specifying the column names. By using the * symbol, we can select all the columns from a table

In this example we will assume that the 'Employees' table contains the follow columns: 'Name', 'Position', 'Office' and 'Salary'. SELECT *
FROM Employees
Here is a sample resultset from the above SELECT query:

NamePositionOfficeSalary
Joe GrapeManagerHouston80000
John PlumSoftware DeveloperHouston65000
Frank AppleSoftware DeveloperCleveland62000
Patty PineappleSoftware DeveloperCleveland60000
Judy PeachSoftware DeveloperBoston50000
Jane OrangeProject ManagerHouston75000

Limiting Rows - WHERE clause

The WHERE clause acts as a filter on the resultset. By adding a WHERE clause after the FROM keyword, the resultset can be limited to rows that meet particular conditions.

This example will select the 'Name', 'Position' and 'Salary' columns' content from the 'Employees' table, where the employee's Position is 'Manager'. SELECT Name, Position, Salary
FROM Employees
WHERE Position = 'Manager'
Here is a sample resultset from the above SELECT query:

NamePositionSalary
Joe GrapeManager80000


This example will select the 'Name', 'Position' and 'Salary' columns' content from the 'Employees' table, where the employee's Salary is greater than 61,000. SELECT Name, Position, Salary
FROM Employees
WHERE Salary > 61000
Here is a sample resultset from the above SELECT query:
NamePositionSalary
Joe GrapeManager80000
John PlumSoftware Developer65000
Frank AppleSoftware Developer62000
Jane OrangeProject Manager75000


MICROSOFT SQL SERVER 2014 STANDARD W/5 CAL’s

Price: $249.99
Buy It Now
Microsoft SQL Server 2014 Standard Edition Server R2 w/20 CAL’s

Price: $641.99
Buy It Now
MSFT SQL Server 2016 Standard Edition x64 64bit | 10 CAL USERS Edition

Price: $499.99
Buy It Now
SQL Server 2014 Standard Edition, Media & License | 32 bit & 64 bit | 10CAL

Price: $399.99
Buy It Now
MSFT SQL Server 2012 Standard Edition, 32bit & 64bit, 16 Core Unlimited User CAL

Price: $999.99
Buy It Now
Microsoft SQL Server 2012 Standard +Microsoft USB +|10 or 25CAL Certificate| NEW
Price: $929
Buy It Now







Copyright 2017 - TSQLTutorials.com