- T-SQL - Numeric Functions
- T-SQL - Date Functions
- T-SQL - String Functions
- T-SQL - Functions
- T-SQL - Indexes
- T-SQL - Transactions
- T-SQL - Stored Procedures
- T-SQL - Sub-Queries
- T-SQL - Joining Tables
- T-SQL - DISTINCT Clause
- T-SQL - GROUP BY Clause
- T-SQL - ORDER BY Clause
- T-SQL - LIKE Clause
- T-SQL - WHERE Clause
- T-SQL - DELETE Statement
- T-SQL - UPDATE Statement
- T-SQL - SELECT Statement
- T-SQL - INSERT Statement
- T-SQL - Drop Tables
- T-SQL - Create Tables
- T-SQL - Data Types
- T-SQL - Overview
- T-SQL - Home
T-SQL Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
T-SQL - SELECT Statement
SQL Server SELECT statement is used to fetch the data from a database table which returns data in the form of result table. These result tables are called result-sets.
Syntax
Following is the basic syntax of SELECT statement −
SELECT column1, column2, columnN FROM table_name;
Where, column1, column2...are the fields of a table whose values you want to fetch. If you want to fetch all the fields available in the field, then you can use the following syntax −
SELECT * FROM table_name;
Example
Consider the CUSTOMERS table having the following records −
ID NAME AGE ADDRESS SALARY 1 Ramesh 32 Ahmedabad 2000.00 2 Khilan 25 Delhi 1500.00 3 kaushik 23 Kota 2000.00 4 Chaitap 25 Mumbai 6500.00 5 Hardik 27 Bhopal 8500.00 6 Komal 22 MP 4500.00 7 Muffy 24 Indore 10000.00
Following command is an example, which would fetch ID, Name and Salary fields of the customers available in CUSTOMERS table −
SELECT ID, NAME, SALARY FROM CUSTOMERS;
The above command will produce the following output.
ID NAME SALARY 1 Ramesh 2000.00 2 Khilan 1500.00 3 kaushik 2000.00 4 Chaitap 6500.00 5 Hardik 8500.00 6 Komal 4500.00 7 Muffy 10000.00
If you want to fetch all the fields of CUSTOMERS table, then use the following query −
SELECT * FROM CUSTOMERS;
The above will produce the following output.
ID NAME AGE ADDRESS SALARY 1 Ramesh 32 Ahmedabad 2000.00 2 Khilan 25 Delhi 1500.00 3 kaushik 23 Kota 2000.00 4 Chaitap 25 Mumbai 6500.00 5 Hardik 27 Bhopal 8500.00 6 Komal 22 MP 4500.00 7 Muffy 24 Indore 10000.00Advertisements