Solved

writing t-sql joins

Posted on 2014-03-25
5
222 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
[X]
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
  • 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

739 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