You are on page 1of 3

OUTER JOINS

LEFT OUTER JOIN/LEFT JOINX

All the records from left table and matching record from right table
It also fetch records from the left table if no matching records from the right table.

SELECT * FROM dep_1148 LEFT OUTER JOIN empl_1148 ON dep_1148.dep_id=empl_1148.dep_id;

WITHOUT MATCHING RECORDS IN RIGHT TABLE

SELECT * FROM dep_1148 LEFT OUTER JOIN empl_1148 ON empl_1148.dep_id=8;

RIGHT OUTER JOIN/RIGHT JOIN

All the records from right table and matching record from left table
It also fetch records from the right table if no matching records from the left table.

SELECT * FROM dep_1148 RIGHT OUTER JOIN empl_1148 ON dep_1148.dep_id=empl_1148.dep_id;


WITH NO RECORD MATCHING

SELECT * FROM dep_1148 RIGHT OUTER JOIN empl_1148 ON dep_1148.dep_id=7;

INNERJOIN/JOIN/EQUI JOIN

selects records that have matching values in Two or more tables

SELECT a.emp_id,a.first_name,b.dep_lead,b.dep_name FROM empl_1148 a INNER JOIN dep_1148 b


ON a.dep_id=b.dep_id;

USING WHERE IN INNER JOIN

SELECT a.emp_id,a.first_name,b.dep_lead,b.dep_name,a.salary FROM empl_1148 a INNER JOIN


dep_1148 b ON a.dep_id=b.dep_id WHERE a.salary>20000;

GROUP BY,HAVING AND ORDER BY IN INNERJOIN


SELECT COUNT(a.dep_id) count,b.dep_name FROM empl_1148 a INNER JOIN dep_1148 b ON
a.dep_id=b.dep_id GROUP BY b.dep_name HAVING COUNT(a.dep_id)> 2 ORDER BY count;

You might also like