Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

writing t-sql joins

Posted on 2014-03-25
5
Medium Priority
?
234 Views
Last Modified: 2014-03-25
I can re-write an inner join statement as below:
inner join statement:
  SELECT t1.id, t2.id
  FROM table1 t1
  JOIN table2 t2 on t1.id = t2.id

same statement:
  SELECT t1.id, t2.id
FROM table1, table2
WHERE table1.id = table2.id AND

Are there other joins I rewrite and is there any advantage to doing so?
0
Comment
Question by:dhenderson12
  • 3
  • 2
5 Comments
 
LVL 49

Accepted Solution

by:
PortletPaul earned 2000 total points
ID: 39953171
You should use the top (first) example which is "ANSI join syntax".

The lower example is also allowed and pre-dates adoption of the ANSI standard - but it is a flawed approach and isn't considered best practice today.
0
 

Author Comment

by:dhenderson12
ID: 39953192
why is it a flawed approach?
0
 
LVL 49

Expert Comment

by:PortletPaul
ID: 39953194
why is it flawed? try this:

oops, forgot something - but it still runs as a query (as a Cartesian join)
  SELECT t1.id, t2.id
FROM table1, table2

the equivalent is:
  SELECT t1.id, t2.id
  FROM table1 t1
  JOIN table2 t2 on

it doesn't let you forget the needed conditions.
0
 

Author Comment

by:dhenderson12
ID: 39953203
I see the problem. Thanks.
0
 
LVL 49

Expert Comment

by:PortletPaul
ID: 39953206
& Let me put it another way.

I would not hire anyone who does not use and understand ANSI join syntax. No exceptions.
I (and the company I work for) will not permit non-ANSI syntax in any of our products.

ANSI join syntax is far better for documenting the query logic and for maintaining the SQL.
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how the fundamental information of how to create a table.

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question