Re: Use ANSI Join or Old Style Join?



ehchn1 wrote:
Hi,

Just curious. Would you use ANSI style table joining or the 'old
fashion' table joining; especially if performance is the main concern?

What I meant is illustrated below:

ANSI Style
select * from a join b on a.id = b.id

Old Style
select * from a, b where a.id = b.id

I noticed that in some SQL, the ANSI is much faster but sometimes, the
old style looks much better.

It's ridiculous to try out both styles to see which is better whenever
we want to write an SQL statement.

Please comment.

Thanks in advance.

I'm interested if you have an example where two otherwise identical
inner joins will yield different execution plans with a resulting
difference in performance. Usually they give equivalent plans whether
you specify the join as INNER JOIN or in the WHERE clause. This is
definitely not true for outer joins however. Always use the OUTER JOIN
syntax instead of the *= notation.

I am aware of two very unusual circumstances where you can get
different results from the INNER JOIN syntax. One is a bug in SQL
Server 2000, the other is with the GROUP BY ALL feature (rarely used in
my experience).

It is incorrect to describe your two queries as ANSI versus "Old
Style". Both are compliant with the ANSI standards SQL92, SQL99 AND
SQL2003. Whether and when to specify join conditions using the INNER
JOIN syntax or not is largely a matter of style and clarity. The
convention I normally use is that if the criteria used for the join is
a foreign key between the two tables then I specify it using in the ON
clause, which therefore requires an INNER JOIN. Otherwise I specfy it
in the WHERE clause, which may mean I can leave out the INNER JOIN. I
don't always follow my own rules though :-)

If an OUTER JOIN is involved as well then it's no longer just a matter
of style. Specifying the same criteria in the WHERE clause versus the
ON clause makes a difference to the meaning of the query if it
references the outer part of an outer join. Maybe that explains what
you are referring to as a performance difference. Can you give a fuller
example? Make sure you specify your SQL Server version and service
pack.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--

.



Relevant Pages

  • Re: ADO error
    ... another dig around shows that SQL Server should handle it as optional. ... While the ANSI 92 standard defines the keyword COLUMN after the ADD as ... statement - with ALTER TABLE ... ... ADD you just specify the column ...
    (microsoft.public.data.ado)
  • Re: Oracle licence question
    ... SS isn't completely ANSI 92 compliant at ... So, I guess let me rephrase the question - does Oracle have ENTRY, ... INTERMEDIATE and FULL compliance to FIPS 127-2 because I can only find ... SQL Server MVP ...
    (comp.databases.oracle.server)
  • Re: Help on sppeding up a 15,000 line batch process
    ... Since everything's so prorietary, the only interface I ... > SQL server in ANSI format and never use unicode... ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Oracle licence question
    ... I did and I couldn't find the citation, which is why I asked you for it. ... I want to check what level of ANSI compliance MS claims, to validate your claim that their implementation of SQL is somehow more the ANSI standard compliant than Oracle's. ... Oracle - http://www.itjobswatch.co.uk/jobs/uk/oracle.do ... SQL Server - http://www.itjobswatch.co.uk/jobs/uk/sql%20server%20dba.do ...
    (comp.databases.oracle.server)
  • Re: Oracle licence question
    ... What level of ANSI 92 or didn't you know there are different levels? ... SQL Server - http://www.itjobswatch.co.uk/jobs/uk/sql%20server%20dba.do ... you ought to compare Oracle DBA with SQL Server DBA and ... starts to get a bit interesting and bias toward Oracle starts to be shown, ...
    (comp.databases.oracle.server)