SQL Server - SELECT Keyword
The SQL Server (Transact-SQL) SELECT keyword is used to select data from a database table and the selected data is returned in the form of a table.
Syntax
The syntax for using SELECT keyword in different scenarios in SQL Server (Transact-SQL) are given below:
/*select one column*/ SELECT column1 FROM table_name; /*select multiple columns*/ SELECT column1, column2, ... FROM table_name; /*select all columns of a table*/ SELECT * FROM table_name;
Example:
Consider a database table called Employee with the following records:
EmpID | Name | City | Age | Salary |
---|---|---|---|---|
1 | John | London | 25 | 3000 |
2 | Marry | New York | 24 | 2750 |
3 | Jo | Paris | 27 | 2800 |
4 | Kim | Amsterdam | 30 | 3100 |
5 | Ramesh | New Delhi | 28 | 3000 |
6 | Huang | Beijing | 28 | 2800 |
-
To fetch Name and Salary data of the employees present in the Employee table, the query is:
SELECT Name, Salary FROM Employee;
This will produce the result as shown below:
Name Salary John 3000 Marry 2750 Jo 2800 Kim 3100 Ramesh 3000 Huang 2800 -
To fetch all fields of the Employee table, the query will be:
SELECT * FROM Employee;
This result of the following code will be:
EmpID Name City Age Salary 1 John London 25 3000 2 Marry New York 24 2750 3 Jo Paris 27 2800 4 Kim Amsterdam 30 3100 5 Ramesh New Delhi 28 3000 6 Huang Beijing 28 2800
❮ SQL Server Keywords