JOINS
 A JOIN clause is used to combine rows from two or more tables,
based on a related column between them.
 SQL JOIN is used when the data
from two tables is to be compared,
the tables must have a common
row.
 INNER JOIN
 LEFT JOIN
 RIGHT JOIN
 FULL JOIN
 SELF JOIN
The INNER JOIN keyword selects
records that have matching
values in both tables.
 SELECT column name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.c
olumn_name;
The LEFT JOIN keyword returns
all records from the left table
(table1), and the matched
records from the right table
(table2). The result is NULL from
the right side, if there is no
match.
 SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.c
olumn_name;
The RIGHT JOIN keyword returns
all records from the right table
(table2), and the matched
records from the left table
(table1). The result is NULL from
the left side, when there is no
match.
 SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.c
olumn_name;
The FULL JOIN keyword returns
all records when there is a
match in left (table1) or right
(table2) table records.
 SELECT column_name(s)
FROM table1
FULL JOIN table2
ON table1.column_name = table2.c
olumn_name
WHERE condition;
 A self JOIN is a regular join, but the
table is joined with itself.
 SELECT column_name(s)
FROM table1 T1, table1 T2
WHERE condition;

Joining

  • 1.
  • 2.
     A JOINclause is used to combine rows from two or more tables, based on a related column between them.
  • 3.
     SQL JOINis used when the data from two tables is to be compared, the tables must have a common row.
  • 4.
     INNER JOIN LEFT JOIN  RIGHT JOIN  FULL JOIN  SELF JOIN
  • 5.
    The INNER JOINkeyword selects records that have matching values in both tables.
  • 6.
     SELECT columnname(s) FROM table1 INNER JOIN table2 ON table1.column_name = table2.c olumn_name;
  • 7.
    The LEFT JOINkeyword returns all records from the left table (table1), and the matched records from the right table (table2). The result is NULL from the right side, if there is no match.
  • 8.
     SELECT column_name(s) FROMtable1 LEFT JOIN table2 ON table1.column_name = table2.c olumn_name;
  • 9.
    The RIGHT JOINkeyword returns all records from the right table (table2), and the matched records from the left table (table1). The result is NULL from the left side, when there is no match.
  • 10.
     SELECT column_name(s) FROMtable1 RIGHT JOIN table2 ON table1.column_name = table2.c olumn_name;
  • 11.
    The FULL JOINkeyword returns all records when there is a match in left (table1) or right (table2) table records.
  • 12.
     SELECT column_name(s) FROMtable1 FULL JOIN table2 ON table1.column_name = table2.c olumn_name WHERE condition;
  • 13.
     A selfJOIN is a regular join, but the table is joined with itself.
  • 14.
     SELECT column_name(s) FROMtable1 T1, table1 T2 WHERE condition;