Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

writing t-sql joins

Posted on 2014-03-25
5
220 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 48

Accepted Solution

by:
PortletPaul earned 500 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 48

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 48

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

789 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