–Types of JOINS and its syntax
–Natural join:
•USING clause•ON clause–Self-join
–Nonequijoins
–OUTER join:
•LEFT OUTER join•RIGHT OUTER join•FULL OUTER join–Cartesian product
Cross joinCreating Natural Joins:
–The NATURAL JOIN clause is based on
all columns in the two tables that have the same name.
–It selects rows from the two tables that have equal
values in all matched columns.
If the columns having
the same names have different data types, an error is returned.
RETRIEVING THE RECORDS WITH NATURAL JOIN
SELECT department_id, department_name,
location_id, city
FROM
departments
NATURAL JOIN locations ;
Creating
Joins with the USING Clause
–If several columns have the same names but the data
types do not match, natural join can be applied using the USING clause to specify
the columns that should be used for an equijoin.–Use the USING clause to match only one column when more than one
column matches.–The NATURAL JOIN and USING clauses are mutually
exclusive.
SELECT employee_id, last_name,
location_id, department_id
FROM
employees JOIN departments
USING (department_id)
Creating
Joins with the ON Clause
No comments:
Post a Comment