Professional Documents
Culture Documents
A STYDY ON
The
Certificate
This is to certify that Mr. VISHAL DIGAMBAR CHAVARE
Seal of Institute
Index…
1 Introduction
2 What is join?
3 Advantages of join
4 Types of joins
One of the biggest issues beginning SQL writers have is being able to write queries
that use more than one table, that is to use database joins. In this series of articles
we are going to show you how to write a query that combines, or joins, data from
more than one table. Once you have gone through the examples you will understand
how to write the basic commands to make this happen and why data is separated in
the first place.
This first article introduces the concept of joining tables. The focus is going to be
more on the type of joins, not necessarily their syntax. The later articles focus on the
various types of joins. Through the narrative and examples you’ll become very
comfortable with each one.
What is join?
Advantages of joins:
1.Using JOINS, you can fetch exactly the data you want from any number of tables
with just one query, using any search parameter you chose to filter the results.
MySQL can also utilize things such as Indexes to maximize performance, which your
API code can not.
2. There is another advantage to the use of joins. By using joins instead of multiple
queries, you maximize the placement of the calculation burden on the database. This
means you can make better use of the database's abilities to search through, filter,
sort, etc.
Types of joins:
1.Inner join
2.outer join
3.left outer join
4.Right outer join
5.Full outer join
Suppose , you want to get list of members who have rented movies together with
titles of movies rented by them. You can simply use an INNER JOIN for that, which
returns rows from both tables that satisfy with given conditions.
Note the above results script can also be written as follows to achieve the same
results.
. The LEFT JOIN returns all the rows from the table on the left even if no matching
rows have been found in the table on the right. Where no matches have been
found in the table on the right, NULL is returned .
Executing the above script in MySQL workbench gives.You can see that in the
returned result which is listed below that for movies which are not rented, member
name fields are having NULL values. That means no matching member found
members table for that particular movie.
Jones 33 Engineering 33
Rafferty 31 Sales 31
Robinson 34 Clerical 34
Smith 34 Clerical 34
Heisenberg 33 Engineering 33
Alternative syntaxes[
Oracle supports the deprecated[8] syntax:
SELECT *
FROM employee, department
WHERE employee.DepartmentID = department.DepartmentID(+)
SELECT *
FROM employee, department
WHERE employee.DepartmentID *= department.DepartmentID
SELECT *
FROM employee, OUTER department
WHERE employee.DepartmentID = department.DepartmentID
Right outer join and example:
RIGHT JOIN is obviously the opposite of LEFT JOIN. The RIGHT JOIN returns all the
columns from the table on the right even if no matching rows have been found in the
table on the left. Where no matches have been found in the table on the left, NULL is
returned.
In our example, let's assume that you need to get names of members and movies
rented by them. Now we have a new member who has not rented any movie yet .
Executing the above script in MySQL workbench gives the following results.
SELECT *
FROM employee RIGHT OUTER JOIN department
ON employee.DepartmentID = department.DepartmentID;
Smith 34 Clerical 34
Jones 33 Engineering 33
Robinson 34 Clerical 34
Heisenberg 33 Engineering 33
Rafferty 31 Sales 31
Right and left outer joins are functionally equivalent. Neither provides any
functionality that the other does not, so right and left outer joins may replace each
other as long as the table order is switched.
Full outer join and example:
In SQL the FULL OUTER JOIN combines the results of both left and rigth outer joins and
returns all (matched or unmatched) rows from the tables on both sides of the join clause.
Syntax:
SELECT *
FROM table1
FULL OUTER JOIN table2
ON table1.column_name=table2.column_name;
Syntax diagram - FULL OUTER JOIN
ON table_A.A=table_B.A;
Copy
Output:
Because this is a full join, all rows (both matching and nonmatching) from both tables are
included in the output. There is only one match between table table_A and table table_B,
so only one row of output displays values in all columns. All remaining rows of output
contain only values from table table_A or table table_B, with the remaining columns set to
missing values
Smith 34 Clerical 34
Jones 33 Engineering 33
Robinson 34 Clerical 34
Heisenberg 33 Engineering 33
Rafferty 31 Sales 31
3.https://en.wikipedia.org/wiki/Join_(SQL)