Q
Problem solve Get help with specific problems with your technologies, process and projects.

What's the difference between an SQL inner join and equijoin?

Can you please explain the difference between an equijoin and an inner join in SQL?

They are unrelated.

Almost every join is an equijoin, because the condition for matching rows is based on the equality of two values—one from each of the tables being joined. So that's what makes it an equijoin: the ON condition is equality. This includes inner joins and all three types of outer joins.

Inner joins, on the other hand, can be based on equality to match rows, or on some other condition entirely. If it's not an equijoin, then it's usually called a theta join, although to be precise, an equijoin is just one of the possible theta joins; other theta joins use less than, less than or equal, etc., as the comparison operator. As long as the comparison evaluates to TRUE, the matched rows qualify for the join.

Here's an example. Suppose we have a table of cities, and amongst all the columns of data for a city, is one called avg_temp, which gives the city's average temperature. Then we could list our cities, and for each city, give a count of how many cities are hotter.

SELECT this.cityname
     , this.avg_temp
     , COUNT(others.cityname) AS hotter_cities
  FROM cities AS this
LEFT OUTER
  JOIN cities AS others
    ON others.avg_temp > this.avg_temp
GROUP
    BY this.cityname
     , this.avg_temp

This must, of course, be an outer join, otherwise the hottest city would have no matching rows (no other cities would be hotter).

Look at the join condition in the ON clause. It is not equality, so this is a theta join.

This was last published in December 2008

Dig Deeper on Oracle development languages

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close