SQL Day 7 Subquries and Date Functions - Queries
SQL Day 7 Subquries and Date Functions - Queries
--1. Single Row Sub Query - one row Query with Simple Sub Query
Select * from Employees
Select Max(Salary)from Employees
Select * from Employees Where Salary = (Select Max(Salary)from Employees)
--2. NeSted Sub Query - will Have a Where Condition inside the Select Satement and
again a select Statement inside the where Condition It can be Used "n" Number of
times
Select * from Employees Where Salary = (Select Max(Salary)from Employees)
--3. Multiple column sub queries - Which can Acesses two or More Colum at a single
time
select * from employees where (department_id,salary) in (select
department_id,max(salary) from employees group by department_id)
--4.Inline View - The Query contain From Statement inside select Select Statement
is called inline view.
select max(sal) from (select department_id,max(salary)sal from employees group by
department_id)
--5. Scalar Sub Query - The Query contain Select statement inside the select
statement that is called scalar sub query.
select first_name,salary,(select Max(salary) MAX_Salary from employees) from
employees
--6. corelated subquery - Outer query refer inner query value or inner query refer
the outer valuse that is called co related sub query
Select * from Employees
Select * from Departments
select department_name from departments d where department_id in (select
department_id from employees where department_id=d.department_id)
--2. SYSTIMESTAMP - Returns the date and time of the system date
Select Systimestamp from dual
Select Systimestamp from Employees
--5. LOCAL TIME STAMP - Our timezone date time and date in the session time zone
Select Localtimestamp from Dual
Select Localtimestamp from Employees
--6. DATA BASE TIME ZONE - Wrirtten Difference Between database Time Zone & Local
Time Zone
Select dbtimezone from Dual
Select dbtimezone from Employees