Table Joins and Indexes in SQL: Class - 12
Table Joins and Indexes in SQL: Class - 12
In above given example there are two tables namely emp1 and dept.
In emp1 table, primary key is empcode and in table dept foreign key is
empcode which is referring empcode of emp1 table.
Making Table ready for join
By analyzing
the tables we
will be informed
that how table
are joined here.
Condition is to
be used to filter
this data.
Join query
To get the details about the departments and their in- charges, query
will be-
When both the tables have same field name, then to show a field
from particular table, use the following pattern to access a field-
<Table name>.<Field Name>
Ex- emp1.empcode
This is an example of Equi-
Join, in which columns are
compared for equality and
it is also an example of
Natural- Join, in which only
one of the identical columns
exists.
Additional search with Join Query
If you want to get information that Ankit is in-charge of which
department, following query will be used.-
Right-JOIN
• When we use RIGHT-JOIN, it returns all rows from second table whether it has
matching rows in first table or not.
• It shows NULL in columns for the unmatched rows of second table.