SQL Server Select Query

MS SQL Server - SELECT Statement

SQL Server provides the SELECT statement to access and retrieve data from a database.

SELECT statement prompts the SQL Server to query a single table or multiple tables in the database.

SELECT Syntax

SELECT [ALL | DISTINCT] column1, column2 ... columnN
       [INTO new_table_name]
[FROM  {table_name | view_name}, {table_name | view_name}...]
       [WHERE clause]
[GROUB BY clause]
[HAVING clause]
[ORDER BY clause]
[COMPUTE clause]

Selecting Some Columns in the Table

SELECT Statement is used to retrieve specific columns from the table.

SELECT column_name1 [, column_name2, ..]
FROM table_name

Selecting Columns in the table

Syntax:
SELECT column1[, column2, ...]
FROM table_name

SELECT Statement Example

Selecting the columns Id, Name, and DeptId in the database table 'Employee'.
SELECT Id, Name, DeptId, Email
FROM Employee
Output:
Select statement output
Selecting the columns Id, Name and Head in the database table 'Department'.
SELECT Id, Name, Head
FROM Deaprtment
Output:
Select statement output

Selecting All Columns

Selecting all the columns Id, Name, DeptId and Email in the database table 'Employee'.
SELECT *
FROM Employee
Output:
Select statement output
Selecting all the columns Id, Name, and Head in the database table 'Department'.
SELECT *
FROM Department
Output:
Select statement output

Using Literals in SELECT Statement

SELECT statement result can be made more readable by including a string called a literal.

Literal can be specified using single quotes and it is printed in the SELECT Statement result as specified.

SELECT column_name | 'string literal'[, column_name | 'string literal', ..]
FROM table_name

Using Literal Example

SELECT Id, Name, 'Department ID:', DeptId
FROM Employee
Output:
Select statement output



Python installation

Privacy Policy  |  Copyrightcopyright symbol2020 - All Rights Reserved.  |  Contact us   |  Report website issues in Github   |  Facebook page   |  Google+ page

Email Facebook Google LinkedIn Twitter
^