ALERT

[LAST CHANCE] Data Layer: Modern Business, Defined

Join

Definition - What does Join mean?

A join is an SQL operation performed to establish a connection between two or more database tables based on matching columns, thereby creating a relationship between the tables. Most complex queries in an SQL database management system involve join commands.

There are different types of joins. The type of join a programmer uses determines which records the query selects. Three algorithms work behind join operations: hash join, sort-merge join and nested loop join.

Techopedia explains Join

The default join type is the inner join. An inner join selects records from two tables that hold matching values. Records that do not hold matching or common values are excluded from the output. The query compares each row of the first table with rows of the second table to find rows to satisfy the join predicate.

For instance, if one table contains employee details and another contains manager information, a join can be performed on the employee and manager tables to display employees who are also managers. The following query displays employees who are managers:

SELECT * FROM Employee INNER JOIN Manager ON Employee.Managerid = Manager.Managerid

A join is always performed on matching columns, which are specified in the "ON" clause of the query. The matching column in this example is "Managerid". Since the ‘=’ operator is used, it is called an equijoin.

A natural join also produces the same output but uses a "USING" keyword in the joining clause. The above query can be modified as follows to indicate a natural join:

SELECT employee, manager FROM Employee INNER JOIN Manager USING (Managerid)

Even if a matching column is not specified, a join is still performed between two tables. This type of join is known as a cross join (sometimes called a Cartesian product), which is the simplest form of join. Because a constraint on the key is not specified, every row in the first table is joined with all rows in the second table. If the first table has two rows and the second table has three rows, the output will have six rows.

The outer join is another important join type. Outer joins, in general, take in all records of one table and matching records of the other table as output. An outer join can be either a left outer join or right outer join. In a left outer join, all tables of the left table - even if they do not satisfy the matching conditions - and the matching rows of the right table are displayed in the output. In a right outer join, all rows of the right table and matching rows of the left table are displayed as output.

In rare cases, a table can be joined to itself. This is called a self-join.

Techopedia Deals

Connect with us

Techopedia on Linkedin
Techopedia on Linkedin
Tweat cdn.techopedia.com
"Techopedia" on Twitter


'@Techopedia'
Sign up for Techopedia's Free Newsletter!

Email Newsletter

Join thousands of others with our weekly newsletter

Resources
The 4th Era of IT Infrastructure: Superconverged Systems
The 4th Era of IT Infrastructure: Superconverged Systems:
Learn the benefits and limitations of the 3 generations of IT infrastructure – siloed, converged and hyperconverged – and discover how the 4th...
Approaches and Benefits of Network Virtualization
Approaches and Benefits of Network Virtualization:
Businesses today aspire to achieve a software-defined datacenter (SDDC) to enhance business agility and reduce operational complexity. However, the...
Free E-Book: Public Cloud Guide
Free E-Book: Public Cloud Guide:
This white paper is for leaders of Operations, Engineering, or Infrastructure teams who are creating or executing an IT roadmap.
Free Tool: Virtual Health Monitor
Free Tool: Virtual Health Monitor:
Virtual Health Monitor is a free virtualization monitoring and reporting tool for VMware, Hyper-V, RHEV, and XenServer environments.
Free 30 Day Trial – Turbonomic
Free 30 Day Trial – Turbonomic:
Turbonomic delivers an autonomic platform where virtual and cloud environments self-manage in real-time to assure application performance.