1.

What is a Join? List its different types.

Answer»

The SQL Join clause is used to combine RECORDS (rows) from two or more tables in a SQL database based on a related column between the two.

There are four different TYPES of JOINs in SQL:

  • (INNER) JOIN: Retrieves records that have matching values in both tables involved in the join. This is the WIDELY used join for queries.
SELECT *FROM Table_AJOIN Table_B;SELECT *FROM Table_AINNER JOIN Table_B;
  • LEFT (OUTER) JOIN: Retrieves all the records/rows from the left and the matched records/rows from the right table.
SELECT *FROM Table_A ALEFT JOIN Table_B BON A.col = B.col;
  • RIGHT (OUTER) JOIN: Retrieves all the records/rows from the right and the matched records/rows from the left table.
SELECT *FROM Table_A ARIGHT JOIN Table_B BON A.col = B.col;
  • FULL (OUTER) JOIN: Retrieves all the records where there is a match in either the left or right table.
SELECT *FROM Table_A AFULL JOIN Table_B BON A.col = B.col;


Discussion

No Comment Found