Thursday 10 March 2016

Select INTO

Selects or copy the data from one table to another.


Select * INTO EMP_DB2 From EMP_DATABASE; 

Copies the data from EMP_DATABASE to EMP_DB2

 

Aliases Name

The name given to the table or column for temporary result set.

Example

Select EMP_Name as Employee_Name From EMP_DATABASE;


Select ABC.EMP_NAME From EMP_DATABASE as ABC;

 

Between Operator

Specifies the range and selects data within it.


Select * From STUDENT_DATBASE
Where Marks BETWEEN 20 AND 40;

NOT keyword can also be used to exclude the range




Select * From STUDENT_DATBASE
Where Marks NOT BETWEEN 20 AND 40;

IN Operator

Multiple values can be specified with the Where clause

Example

Select * From EMP_DATABASE Where EMP_ID in ('AVX550', 'AV2551');

Like Operator

This operator can be use to search for specified pattern from data set.
Example
Select * From EMP_DATABASE Where EMP_Name LIKE 'R%'
Displays the result where Employee name start with R alphabet

Select * From EMP_DATABASE Where EMP_Name LIKE '%R'
Displays the result where Employee name ends with R alphabet

Select * From EMP_DATABASE Where EMP_Name LIKE '%R%'
Displays the result where Employee name contains R alphabet

TOP Clause

Limits the number of Rows in the result set based on criteria or percentage specified


Select TOP 3 * From EMP_DATABASE

Select TOP 20 Percent * From EMP_DATABASE

Delete Statement

Delete statement allows you to delete rows from the existing table.
Example
Delete From EMP_DATABASE
Where EMP_NAME ='Ramneek'
To delete all records
Delete * From EMP_DATBASE (Only Records deleted not Table)

UPDATE Keyword

UPDATE keyword is used to update the records already in the database. Where caluse should always be specifed to update the existing record as this may even create column or data lock.

Example

Update EMP_Database
Set EMP_NAME = 'Ramneek'
Where EMP_NAME='Rakesh'


This query will update EMP_NAME as Ramneek Where EMP_Name as Rakesh

INSERT INTO


INSERT INTO allows you to enter new records in the Database.

INSERT INTO EMP_DATABASE (EMP_NAME, EMP_ID) Values ('Ramneek','AVN7778');


 

ORDER BY Keyword

The keyword can be use to sort the result in ASC/DESC order. By Default the result is populated in ascending order.

Select * From EMP_DATABASE  ORDER BY EMP_NAME;

Select * From EMP_DATABASE ORDER BY EMP_NAME DESC;

Select * From EMP_DATABASE ORDER BY EMP_NAME ASC, EMP_ID DESC

 

OR Keyword

This condition build the choice between two options by specifying the OR keyword in the select statement.
 
 
 
Example
 
 
Select * From EMP_Database Where EMP_NAME ='Ramneek' OR EMP_NAME = 'Rakesh'

AND Keyword

Specifies the selection with AND keyword in which both condition should be matching in the database.

Example

Select * From EMP_Database where EMP_Name='Ramneek' AND Place ='Gurgaon'
 

Where Clause

As the name specify. This keyword is used when we need to build query with spcific criteria.

Example

 Select * From Table_Name Where EMP_ID =AVD330

Select * From EMP_Database Where EMP_Name ="Ramneek Sharma"

 

Distinct Keyword

Distinct keyword allows you to get only different values from the database.

Example

Select  DISTINCT Places from MaterTable_Database



   

Select Statement


Select Statement is used to Pull/Fetch the data from particular  fields in a database.
Example

Select * From Table_Name;  ( * Retrieve all the columns from the Table)   
Select  EMP_ID,  Contact_Details From EMPDatabase; ( Retrieves Only Columns EMP_ID & Contact_Details from EMPDatabase Table)