Select statement in MS SQL Server


Select statement is a one of the basic statements of SQL Server. Select statement we used to select data from table.

SQL Select statement return data in tabular format.


Select all columns from table


Let consider we have the product table, and we need to select data from table.

Example

SELECT * FROM tblShoppingList

Output

select data from physical table in sql server


Note : In above example * indicate all columns from respected table.


Select statement create alias on column level using AS keyword.

Select only ProductName, Price, Discount and create new columns and give name with alias as FinalPrice.

Example

SELECT ProductName, Price AS 'ActualPrice' ,
Discount , (Price - Discount ) AS 'FinalPrice'
FROM tblShoppingList

Output

create alias on column level and select sql column with table alias


Note : In above example we change the Price column name to 'ActualPrice' using alias (AS).


Select statement create alias on table level using AS keyword.

Above same example we use in to create table alias.

Example

SELECT SL.ProductName, SL.Price AS 'ActualPrice' ,
SL.Discount , (SL.Price - SL.Discount ) AS 'FinalPrice'
FROM tblShoppingList AS SL

Output

create alias on table level and select specific column from table


Note : When we create alias on table level then we have to use the selected columns name with table name alias.
Example. SL.ProductName.
Hear, SL is alias of table and ProductName is the column name.