Define delete statement


The DELETE statement in used to delete the rows in a database table.

Example :

Delete from Employees where EmployeeName = ‘Peterson’
This Query will delete the row that is having employee name as “Peterson”
All the rows in a table can be deleted like,
Delete * from Employees

Or

Delete from Employees
This Query will delete all the rows in “Employees” table

Define order by statement

The ORDER BY clause is used to sort the output in the specified manner like ascending or

descending.

Select EmployeeName, EmployeeID from Employees order by EmployeeName Desc

This Query will display the Employee names in reverse alphabetical order

Select EmployeeName, EmployeeID from Employees order by EmployeeName Desc, EmployeeID Asc

This Query will display the Employee names in reverse alphabetical order and the Employee ID in

alphabetical order.

What is the difference between UNION and UNIONALL commands in SQL

The UNION command is used to select the related data from two different tables, while using

the UNION command all the selected columns have to to be of the same data type.

Example :

Select EmployeeName from Employees unionSelect EmployeeName from Department

This Query will display only the distinct Employee names in Employees and Department Tables.

The UNION ALL command is similar to UNION command, but it displays all the values in the

both the tables.

Example :

Select EmployeeName from Employees union allSelect EmployeeName from Department

This Query will display all the Employee names in Employees and Department Tables.

Define AND & OR conditions in SQL

The AND & OR is used to join two or more conditions in a WHERE clause

The AND operator displays a row if ALL the conditions listed are true.

Example :

Select * from Employees where EmployeeName = ‘Steve’ and City = ‘Bangalore’

This Query will display the each person with EmployeeName equal to “Steve” and City equal to

“Bangalore”

The OR operator displays a row if ANY of the conditions listed are true

Example :

Select * from Employees where EmployeeName = ‘Steve’ or City = ‘Bangalore’

This Query will display the each person with EmployeeName equal to “Steve” or City equal to

“Bangalore”.

Define IN operator in SQL

The IN operator is used to compare a column with one or more value. It is similar to

OR condition.

Example :

Select EmployeeName, EmployeeIDfrom Employeeswhere City in (‘Chennai’,

‘Bangalore’)

This Query will display the Employee Name, Employee ID only from city “Chennai”

and “Bangalore”.