Difference between inner join and left join in SQL.




 Difference between inner join and left join:-

INNER JOIN

LEFT JOIN

It will return all the records which have matching values in both the tables based on the specified join condition. It will not return the unmatched records.

It will return all the records from the left table and matched records from the right table. If there are not matched records from the right table, NULL values will be returned. It will also return the unmatched rows from the left table.

Syntax: select table1.column1, table2.column2 FROM table1 INNER JOIN table2 ON table1.common_column=table2.common_column;

Syntax: select table1.column1, table2.column2 FROM table1 LEFT JOIN table2 ON table1.common_column=table2.common_column;

For the complex queries, there must not be performance drop issue.

For the complex queries, there must be performance drop issue.

It is faster than left join because database has to remove all the rows that don’t get match in the inner join.

It is slower than inner join because it will keep all the records and return NULL values for not matched rows.

It is also known as equi join.

It is also known as left outer join.

Missing matches are not returned.

Missing matches are shown as NULL in the right table.

It is less expensive in terms of cost.

It is expensive in terms of performance due to the include of unmatched rows and handling NULL. There is chance of increased cost in case of large data sets with complex queries.


Note:


One should EXPLAIN PLAN in oracle to analyze the join performance.

One should be cautious to use WHERE clause after joins. Where clause can unintentionally convert the LEFT JOIN into an inner join.

PRACTICAL QUERIES:


select e.empno,e.ename,d.dname,d.deptno
from emp e
INNER JOIN
dept d ON e.deptno=d.deptno;





select e.empno,e.ename,d.dname,d.deptno
from emp e
LEFT JOIN
dept d ON e.deptno=d.deptno;




Comments

Popular posts from this blog

Difference between union and union all in oracle sql plsql

Explain oracle pl sql datatypes interview question and answer for fresher and experienced.

Difference between full join and cross join-oracle sql plsql