Editorials

Join Syntax

Did you know that you don’t have to use JOIN syntax when writing a SQL Query? You can simply list your tables, and put the join criteria in the where clause.

In today’s world we typically create a join clause for each table joined after the original first table specified in the from clause. Here’s an example query pulling from order , and joining to person and customer.

SELECT …
FROM    Order
JOIN      Customer ON Order.CustomerId = Customer.CustomerId
JOIN     Person ON Customer.PersonId = Person.PersonId

Using this syntax we define what tales we are returning, what kind of join is being executed, and what criteria is being used to perform the join aspect of the query.

Not too long ago things were not quite as simple. The following query executes the same plan.

SELECT …
FROM    Order, Customer, Person
WHERE Order.CustomerId = Customer.CustomerId
AND Customer.PersonId = Person.PersonId

If you wanted to do inner or outer joins you would use *= or =*. If you wanted a cross join (a join with no criteria) then you didn’t provide any join criteria in you where clause, and everything worked as desired.

This older syntax still works today on SQL Server 2014. I suppose the only advantage is that your older SQL queries can still be executed with confidence.

Cheers,

Ben