Solved

writing t-sql joins

Posted on 2014-03-25
5
215 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
Comment Utility
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
Comment Utility
why is it a flawed approach?
0
 
LVL 48

Expert Comment

by:PortletPaul
Comment Utility
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
Comment Utility
I see the problem. Thanks.
0
 
LVL 48

Expert Comment

by:PortletPaul
Comment Utility
& 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now