SQL – Select Statement
October 29, 2017
Select statement is a DML (Data Manipulation Language) statement.The SELECT statement is an SQL statement that specifies which rows and columns to fetch from one or more tables or views. The SELECT statement is very helpful in finding filtered records from a database.
Features of Select statement :
- It is used for retrieving data from the database either selectively or collectively.
- Column names can be specified or * may be specified for displaying all columns.
- Calculated columns can be displayed.
- Duplication can be removed.
- Sorting of rows is possible.
- Summary information can be displayed
SELECT statement includes a:
- SELECT clause, which lists the columns to be displayed
- FROM clause, which specifies the table involved
- [WHERE] clause, which limits the number of rows returned
- [GROUP BY] clause, which groups the rows based on specified columns
- [HAVING] clause, which specifies the table involved
- [ORDER BY] clause, which sorts the rows based on specified columns
Syntax Of SQL SELECT Statement :
To select all the columns :
SELECT * FROM daily_pipeline_loan_fact;
To select specific columns:
SELECT loanno, loan_amount FROM daily_pipeline_loan_fact;
The DISTINCT clause:
The default output of a SELECT query is all rows including duplicate rows. The DISTINCT keyword is used to eliminate duplicate rows from the output.
SELECT DISTINCT loan_status FROM daily_pipeline_loan_fact;
The Where clause:
- Applies conditions to filter rows
- Appears immediately after the SELECT and FROM clause
- Does not allow alias
SELECT <COLUMN NAME(S)>
FROM <Table name>
WHERE <CONDITION>