SELECT Command - DotNet and DataBase

Wednesday, 1 August 2018

SELECT Command



Select is the most commonly used command in SQL. Select command is used to retrieve data from a table or group of statements. We can fetch entire columns in the table or specified columns from the table.

Syntax:
To get all columns from a table
SELECT * FROM <Tablename>; 

To get particular list of columns from a table
SELECT col1,col2,col3 etc FROM <Tablename>;
Example:
SELECT * FROM EmployeeInfo;
SELECT ID,EmpName,EmpPhone FROM EmployeeInfo;

Result:



Select with alias names:
We can fetch the data from the table by changing the column names run-time. It doesn't impact the original table, but columns would be changed in the result set.

Syntax:
SELECT col1 as <alias name>,col2 as <alias name>,col3 as <alias name> etc FROM <Tablename>;

Example:
SELECT ID as EmpployeeID,EmpName as EmpployeeName,EmpPhone  as EmpployeePhone FROM EmployeeInfo;

Result:


No comments:

Post a Comment

x

Get Updates On

Discussion updates

Straight Into Your INBOX!

Enter your email address to subscribe to this website and receive notifications of new posts by email.