Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

writing t-sql joins

Posted on 2014-03-25
5
Medium Priority
?
232 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 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

How to Create Failover DNS Record Sets in Route 53

Route 53 has the ability to easily configure DNS record sets specifically for failover scenarios. These failover record sets can be configured to failover to full-blown deployments in other regions or to a static HTML page that informs your customers of the issue.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

705 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