SELECT statement.
The SELECT statement is used to access and retrieve data from a database.The syntax of the SELECT statement is:
SELECT [ALL | DISTINCT] select_column_list [INTO [new_table_name]] FROM {table_name | view_name} [WHERE search_condition] where , ALL is represented with an (*) asterisk symbol and displays all the columns of the table. DISTINCT specifies that only the unique rows should appear in the result set.
select_column_list is the list of columns or aggregate columns for which the data is to be listed. INTO creates a new table and inserts the resulting rows from the query into it. new_table_name is the name of the new table to be created. FROM table_name is the name of the table from which the data is to be retrieved. WHERE specifies the search condition for the rows returned by the query. search_condition specifies the condition to be satisfied to return the selected rows.
EX.
SELECT * FROM HumanResources.Employee
Customizing the Display
Sometimes, you may want to change the way data is displayed. For example, if the names of columns are not descriptive, you might need to change the default column headings by creating user
- defined headings.
following ways:
.
- SELECT 'Department Number'= DepartmentID, ' Department Name'= Name FROM HumanResources.Department
- SELECT DepartmentID 'Department Number', Name ' Department Name' FROM HumanResources.Department
- SELECT DepartmentID AS 'Department Number', Name AS ' Department Name' FROM HumanResources.Department
you can use the concatenation operator
. The concatenation operator is used to concatenate string expressions. It is represented by the + sign. To concatenate two strings, you can use the following query: SELECT 'snow ' + 'ball' The preceding query will display snowball as the output.
The following SQL query concatenates the data of the Name and GroupName columns of the Department table into a single column:
SELECT Name + ' department comes under ' + GroupName + ' group' AS Department FROM HumanResources.Department
No comments:
Post a Comment