Top Menu

Search This Blog

SQL Joins

SQL joins are used to combine rows from two or more tables.

When a query includes more than one table, you need to specify how records from the tables are to be matched up to produce the result set. This is called joining the tables. The JOIN sub-clause of SQL-SELECT's FROM clause is used for this purpose.

A join has two parts: the pair of tables to be joined, and the condition for matching records. 

Syntax:

  <Table1>  JOIN  <Table2>  ON  <expression> 

The expression following the ON keyword (called the join condition) matches the primary key (PK) of one table with a foreign key (FK) in another table.

SQL Join Type:
  • LEFT JOIN: Get all record from the left table, and the matched record  from the right table.
  • RIGHT JOIN: Get all record  from the right table, and the matched record  from the left table.
  • FULL JOIN: Get all record  when there is a match in one of the table.
  • INNER JOIN: Get all record  when there is at least one match in both table.

Post a Comment

Designed by OddThemes | Distributed By Gooyaabi Templates