473,800 Members | 3,089 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Use ANSI Join or Old Style Join?

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.

May 20 '06 #1
1 10986
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/m...S,SQL.90).aspx
--

May 20 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2222
by: ColdCanuck | last post by:
Help! I'm trying to understand the new ANSI join syntax (after many years of coding using the old style). I am now working with an application that only understands ANSI syntax so I am struggling. My first (old style syntax) SQL statement below produces 60 rows: SELECT A1.CONTACTID, A1.LASTNAME, A1.FIRSTNAME, A1.ACCOUNT, A6.CITY, A6.STATE, A1.WORKPHONE, A1.FAX, A1.EMAIL
3
1883
by: jakelake | last post by:
Help....I have a DB I'm working with that I know doesn't work with the ANSI-92 JOIN SYNTAX....I'm not sure how much this limits my ability to deal with the following situation, so I'm soliciting the help of a guru....I apologize for the lack of scripted table structure, but this database is embedded in an application that I have no true schema for. I have a crude diagram of the tables and some of the relationships, but I've managed to have...
5
1705
by: RK | last post by:
I need to compile a library of C code with pre-ANSI C functions using MS ..NET 2003. The functions are declared something like this: int myFunction(p) double p; { int x; code here... return x; }
2
6205
by: Martín Marconcini | last post by:
Hello there, I'm writting (or trying to) a Console Application in C#. I has to be console. I remember back in the old days of Cobol (Unisys), Clipper and even Basic, I used to use a program (its name i cannot recall now...) where I designed the "screen" using this "program" and then saved it into an ASCII file. (thus, using 'extended' ASCII's like Lines, Corners, etc. and making screens look nicer and more professional). Then reading a...
4
2013
by: Kza | last post by:
Hi, just in the process of maintaining some software that used some funy old string library and char*s , and we are updating everything to use std::strings. (or should I say std::basic_string<>s) I find it wierd that that all the new c++ ansi style librarys like the streams and file handling classes still expect us to use old style char* type strings. For example, ofstreams open function expects the filename as a char* parameter rather...
15
2961
by: Bart Vandewoestyne | last post by:
I'm having a .c source file which at the top contains the line #include <math.h> In that source file, i declare a function dt which in its body uses the lgamma function. `man lgamma' on my linux system tells me that i have to include math.h so it seems like I'm doing the right thing in order to be able to use the lgamma function. When I compile the .c file with
83
11644
by: sunny | last post by:
Hi All What is C99 Standard is all about. is it portable, i mean i saw -std=C99 option in GCC but there is no such thing in VC++.? which one is better ANSI C / C99? can i know the major difference between C99 & ANSI C standards?
10
3204
by: Michael B. Trausch | last post by:
Alright... I am attempting to find a way to parse ANSI text from a telnet application. However, I am experiencing a bit of trouble. What I want to do is have all ANSI sequences _removed_ from the output, save for those that manage color codes or text presentation (in short, the ones that are ESChttp://fd0man.theunixplace.com/Tmud.tar which contains the code in question. In short, the information is coming in over a TCP/IP socket that...
6
4035
by: dunleav1 | last post by:
I have an application that uses the old join syntax instead of the SQL92 standards join syntax. I need to justify changing the code to the new standard. Is there any performance issue related to using the old syntax that are documented? Are there any other issues that I use to justify a code upgrade?
0
9550
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10495
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10269
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10248
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10032
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7573
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5597
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4148
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.