JoJo
JoJo

Reputation: 4933

when selecting from multiple SQL Server 2008 tables is a join inferred?

I found a sproc in a db that I think infers a table join?

Is that accurate to deduce that from the sample below?

SELECT a.Column1, b.Column2
  FROM [dbo].[Table1] As a,
  [dbo].[Table2] AS b

Upvotes: 0

Views: 69

Answers (3)

Jeff Rosenberg
Jeff Rosenberg

Reputation: 3572

It does infers a join, but that join is a CROSS JOIN, which is rarely what you want. It won't simply map each row of a to its equivalent in b. Instead, it will map each row of a to every row of b. That is a join, but it's not what we often think of when we talk about joins.

I wanted to show a quick example, but unfortunately SQL Fiddle is down. Sorry!

More on cross joins and cartesian products in SQL Server here.

Upvotes: 3

user3248346
user3248346

Reputation:

You inferred correctly, this is a Cartesian join.

Upvotes: 3

rory.ap
rory.ap

Reputation: 35318

Yes, it's called a "Natural Join". You can constrain it with the WHERE clause.

Upvotes: 2

Related Questions