difference between self join and correlated queries
Printable View
difference between self join and correlated queries
Joining a table to itself is known as selft join. The self join can be viewed as a join of two copies of the same table.
SELECT e1.last_name||' works for '||e2.last_name
"Employees and Their Managers"
FROM employees e1, employees e2
WHERE e1.manager_id = e2.employee_id
AND e1.last_name LIKE 'R%';
Correlated queries are subqueries in which inner query is evaluated once per each row processed by the outer query. They take more processing time.
A correlated subquery can return the same result as a self join, but can be used where a join cannot, such as in an UPDATE, INSERT and DELETE statement.
Self join is joining the one table to itself, but when you come to the corealted queries we can use the different tables and in the corelated queries the inner query executes first, but it will dependa on the outer query. so they are interrelated to each other.
self join is done from a single table like if u wana find out the employee id of a manager then we do self join with the table in this only a single table is rquired
where as in coreleted sub query the result is based on the outer query like every time the inner query is exicuted the outer query is executed and the data can be retervied from two tables in subquery we can have difrnt table and vice versa.:):)