Re: Which inner join syntax is more efficent?

From: Ian King (idking_at_telkomsa.net)
Date: 09/12/04


Date: Sun, 12 Sep 2004 21:19:31 +0200

Hi,

[1] You may want to look at Quest - SQL Tuning for SQL Server :
http://www.quest.com/quest_central/sql_server/sql_tuning/
(I think there is a trial version)

It evaluates your SQL, generates multiple semantically equivelant
statements, executes all of them, and selects the most efficient.

[2] Also, use the SET STATISTICS IO ON, when you compare your queries.
This will give you CPU & Page read stats.

[3] In general, I've observed that specifying the expression in the
WHERE clause performs better than in the ON clause. (Although I havent
done it enough times to reach any conclusions...)

thanks

Ian

olduncleamos@yahoo.com wrote:
> Hello all.
>
> Assuming both TableA and TableB are roughly the same size with index
> on COL_1 on both table. Which syntax will be more efficient?
>
> SELECT A.Col_1, B.Col_2 FROM
> TableA AS A INNER JOIN TableB AS B ON A.Col_1 = B.Col_1
> WHERE A.Col_1 = @Some_Value
>
> OR
>
> SELECT A.Col_1, B.Col_2 FROM
> TableA AS A INNER JOIN TableB AS B ON A.Col_1 = B.Col_1 AND A.Col_1 =
> @Some_Value
>
> Any help will be greatly appreciated.



Relevant Pages

  • Re: Finally in IE
    ... If an exception is thrown, each catch clause is inspected in turn ... the clause executes wether or not an exception is thrown ... Firefox considers your <script> block as self-enclosed system. ...
    (comp.lang.javascript)
  • Re: the "having" clause
    ... Start in the FROM clause and build a working table from all of the ... rest of the containing query. ... e) Go to the SELECT clause and construct the expressions in the list. ... As you can see, things happen "all at once" in SQL, not from left to ...
    (microsoft.public.sqlserver.programming)
  • Re: Report Parameters - no results
    ... Allen Browne - Microsoft MVP. ... I did use the WHERE clause you suggested, and now I'm getting the "wrong ... > What else can I do to try to correct my sql? ... >> the WHERE clause in your query. ...
    (microsoft.public.access.reports)
  • =?iso-8859-1?Q?Re:_Abfrage_meherer_MWSt.-S=E4tze?=
    ... der bereits Rechnungen mit x ) Positionen und mehreren Mehrwertsteuersätzen sinnvoll zu gruppieren und zu summieren hatte? ... Obwohl die Hilfe mindestens 70 Einträge zum Thema SQL aufweist, oft mehrere Seiten je Thema bzw. je Befehl mit Querverweisen und auch mit Beispielen geschmückt ist. ...
    (microsoft.public.de.sqlserver)
  • Re: Aliases and the WHERE clause
    ... The one hope we could hold is that future releases of engines will build on ... To me, SQL also feels just like a set of principles, or if you wish, mental ... I was thinking about the ORDER BY clause. ... alias in the WHERE clause. ...
    (microsoft.public.access.queries)