Query : It is an operation that retrieves data from one or more tables or views.
Select statement : The SELECT statement is used to retrieve data from one or more tables, object tables, views, object views or materialized views.
Prerequisites :
- The user must have the select privileges on the specified object.
- The select any table allows to select the data from any recognized object.
Capabilities of SQL SELECT statement:
The SELECT statement can be used to select or retrieve data from the object using any one the following criteria.
SELECTION : It chooses the rows in a table that are expected to return by a query.
PROJECTION : It chooses the columns in a table that are expected to return by a query.
JOIN : It chooses the data from one or more number of tables by creating a link between them.
Basic SELECT Syntax :
SELECT [DISTINCT]{*,column [Alias],.................} From Table;
- SELECT : Identifies column
- FROM : Identifies table
- DISTINCT : suppresses duplicates
- * : Select all columns
- COLUMN : Select the named column
- ALIAS : Gives selected columns different column names
- FROM Table : Specifies the table containing the columns.
To know the column names and data types type below statements
DESC EmpRetrieving Data From All Columns :
DESC Dept
DESC Salgrade
DESC Bonus
SELECT * FROM Emp;
SELECT * FROM Dept;
SELECT * FROM Salgrade;
- In this '*' is a projection operator.
- It projects data from all the columns existing in the table with all records.
- The data is displayed in a table format.
Retrieving Data From Specified Columns :
SELECT Empno, Ename, Sal FROM Emp;
SELECT Empno, Ename, Job,Dept,Sal FROM Emp;
SELECT Deptno, Dname, Loc FROM Dept;
SELECT Hisal, Losal, Grade FROM Salgrade;
- The column names need not be in the same order as table.
- The columns should be separated using comma.
- The column names can be separated onto different lines within the sql buffer.
- The casing of column names is not important.
- The default justification of the data after it is retrieved from the table is
LEFT : Date and Character Data
RIGHT : Numeric Data
- The default display of the data is always is upper casing.
- The character and date column hedings can be truncated, but numbers cannot be truncated.



0 comments
Post a Comment
Do comment to make this blog better