SQL AND & OR Operators
· The AND operator uses to satisfy two conditions. That is it returns true only if two conditions are satisfied.
· The OR operator return true only if one of the conditions are satisfied.
Select * from employee_dtl where department_id=1 and designation_id=3
| Emp_Id | Emp_Name | Department_id | Join_dt | Designation |
| 10254 | Meera | 1 | 09/04/2006 | 3 |
Select * from employee_dtl where department_id=1 or designation_id=3
| Emp_Id | Emp_Name | Department_id | Join_dt | Designation |
| 10001 | Manu | 1 | 06/06/2008 | 1 |
| 10254 | Meera | 1 | 09/04/2006 | 3 |
Select * from employee_dtl where department_id =1 and (designation_id=1 or designation_id=4)
| Emp_Id | Emp_Name | Department_id | Join_dt | Designation |
| 10001 | Manu | 1 | 06/06/2008 | 1 |
The ORDER BY Keyword
· Used to sort the result set by a specified column
· By default it sort in ascending order
· DESC is the keyword used to sort in descending order
SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC|DESC.
Select * from employee_dtl order by join_dt
| Emp_Id | Emp_Name | Department_id | Join_dt | Designation |
| 10254 | Meera | 1 | 09/04/2006 | 3 |
| 10001 | Manu | 1 | 06/06/2008 | 1 |
| 13654 | Thilak | 2 | 09/05/2009 | 4 |
Select * from employee_dtl order by emp_code desc
| Emp_Id | Emp_Name | Department_id | Join_dt | Designation |
| 13654 | Thilak | 2 | 09/05/2009 | 4 |
| 10254 | Meera | 1 | 09/04/2006 | 3 |
| 10001 | Manu | 1 | 06/06/2008 | 1 |
No comments:
Post a Comment