JOIN ON vs USING vs NATURAL JOIN: What’s the Difference?

Probably the most common way to join tables in SQL is with the ON clause. But that’s not the only way.

We can also join with the USING clause, which can be more concise, while providing the same or similar results. And there’s also the concept of a natural join, which is more concise again.

Let’s take a look at these three join options and compare them side by side.

Continue reading

SQL Joins with the USING Clause: How It Compares to the ON Clause

Perhaps one of the lesser-known clauses when it comes to SQL joins is the USING clause. While the more widely-used ON clause allows us to explicitly specify join conditions, the USING clause simplifies the syntax when the join is based on columns with the same name in both tables.

In this article, we’ll dive into the USING clause, compare it to the ON clause, and look at examples that illustrate the difference.

Continue reading

The Difference Between INNER and LEFT JOINs in SQL

SQL joins are fundamental operations in relational databases, allowing us to combine data from multiple tables. Two of the most commonly used join types are INNER JOIN and LEFT JOIN. Understanding the difference between these joins is crucial if you intend to use joins in your queries.

In this article, we’ll look at the difference between the INNER JOIN and LEFT JOIN using a simple example.

Continue reading

Override the Query Optimizer for your T-SQL Joins with FORCEPLAN

The SET FORCEPLAN statement overrides the logic used by the SQL Server query optimizer to process a T-SQL SELECT statement.

More specifically, when FORCEPLAN is set to ON, the query optimizer processes a join in the same order as the tables appear in the FROM clause of a query.

This also forces the use of a nested loop join unless other types of joins are required to construct a plan for the query, or they are requested with join hints or query hints.

Continue reading