List and explain the different types of JOIN.
Inner join: returns only those records that match in both the tables.
SELECT A.*,B.* FROM table_A A INNER JOIN table_B B ON A.aID = B.aID;
Left outer: join returns all records from left table and only matching records from right.
SELECT A.*,B.* FROM table_A A LEFT JOIN table_B B ON A.aID = B.aID;
Right outer: join returns all records from right table and only matching records from left.
SELECT A.*,B.* FROM table_A A RIGHT JOIN table_B B ON A.aID = B.aID;
- Full outer join: combines left outer join and right outer join. This join returns all records/rows from both the tables.
SELECT A.*,B.* FROM table_A A
FULL OUTER JOIN table_B B
ON A.aID = B.aID;
- Cross join: is a cartesian join means cartesian product of both the tables. This join does not need any condition to join two tables.
SELECT A.*,B.* FROM table_A A CROSS JOIN table_B B
- Self join: is used to join a database table to itself
SELECT A.*,B.* FROM table_A A INNER JOIN table_A A2 ON A.aID = A2.pID;