<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; SELECT 1 vs SELECT * &#8211; An Interesting Observation</title>
	<atom:link href="http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Sun, 12 Feb 2012 09:22:39 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: hootsey</title>
		<link>http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/#comment-243409</link>
		<dc:creator><![CDATA[hootsey]]></dc:creator>
		<pubDate>Wed, 25 Jan 2012 11:34:41 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=519#comment-243409</guid>
		<description><![CDATA[To add to this comment on the history of why select 1 is used. select * certainly used to have physical disk IO implications that take time reading the data where as selecting a constant didn&#039;t. This probably isn&#039;t the case now but I still use select 1]]></description>
		<content:encoded><![CDATA[<p>To add to this comment on the history of why select 1 is used. select * certainly used to have physical disk IO implications that take time reading the data where as selecting a constant didn&#8217;t. This probably isn&#8217;t the case now but I still use select 1</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony</title>
		<link>http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/#comment-168780</link>
		<dc:creator><![CDATA[Tony]]></dc:creator>
		<pubDate>Fri, 16 Sep 2011 16:37:03 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=519#comment-168780</guid>
		<description><![CDATA[A bit of history that we all know that SQL Server came from Sybase and that optimizers were not always as good as they are now. So these products have evoloved and been continually enhance over a period of over 20 years.  These &quot;Myths&quot; started many moons ago. I clearly rmember having issues with SQL 6.5 doing EXISTS(SELECT * FROM ...) and fixing these issues by using SELECT 1.  The Optimizers now don&#039;t have these issues but I still use SELECT 1 because vehemently dislike the use of SELECT * in any scenario.]]></description>
		<content:encoded><![CDATA[<p>A bit of history that we all know that SQL Server came from Sybase and that optimizers were not always as good as they are now. So these products have evoloved and been continually enhance over a period of over 20 years.  These &#8220;Myths&#8221; started many moons ago. I clearly rmember having issues with SQL 6.5 doing EXISTS(SELECT * FROM &#8230;) and fixing these issues by using SELECT 1.  The Optimizers now don&#8217;t have these issues but I still use SELECT 1 because vehemently dislike the use of SELECT * in any scenario.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe</title>
		<link>http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/#comment-155362</link>
		<dc:creator><![CDATA[Joe]]></dc:creator>
		<pubDate>Tue, 09 Aug 2011 10:02:04 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=519#comment-155362</guid>
		<description><![CDATA[An advantage of using select 1 instead of select * is that you can do a simple find in your code base and any &#039;select *&#039; will raise a red flag and a visit to the offending developer&#039;s desk :-) A workaround is searching with a regular expression to exclude cases with &#039;exists (&#039; but my regular expression brain can&#039;t figure this out in 2 minutes :-)]]></description>
		<content:encoded><![CDATA[<p>An advantage of using select 1 instead of select * is that you can do a simple find in your code base and any &#8216;select *&#8217; will raise a red flag and a visit to the offending developer&#8217;s desk :-) A workaround is searching with a regular expression to exclude cases with &#8216;exists (&#8216; but my regular expression brain can&#8217;t figure this out in 2 minutes :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rajan</title>
		<link>http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/#comment-124402</link>
		<dc:creator><![CDATA[Rajan]]></dc:creator>
		<pubDate>Tue, 22 Mar 2011 15:17:04 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=519#comment-124402</guid>
		<description><![CDATA[I believe, select 1 is faster if the condition is checking the indexed columns.
In that case, we don&#039;t need to fetch the data from the FS, only read the index(which is the step used anyway) and if true, then output 1. This reduces the step to fetch data from underlying FS

-R]]></description>
		<content:encoded><![CDATA[<p>I believe, select 1 is faster if the condition is checking the indexed columns.<br />
In that case, we don&#8217;t need to fetch the data from the FS, only read the index(which is the step used anyway) and if true, then output 1. This reduces the step to fetch data from underlying FS</p>
<p>-R</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yeoh Ray Mond</title>
		<link>http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/#comment-81635</link>
		<dc:creator><![CDATA[Yeoh Ray Mond]]></dc:creator>
		<pubDate>Sun, 25 Jul 2010 16:00:51 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=519#comment-81635</guid>
		<description><![CDATA[Well, I&#039;ve always used EXISTS 1, simply because it is easier to type compared to *!]]></description>
		<content:encoded><![CDATA[<p>Well, I&#8217;ve always used EXISTS 1, simply because it is easier to type compared to *!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Madhivanan</title>
		<link>http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/#comment-62927</link>
		<dc:creator><![CDATA[Madhivanan]]></dc:creator>
		<pubDate>Mon, 15 Mar 2010 07:16:11 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=519#comment-62927</guid>
		<description><![CDATA[In the Query Analyser PRESS CONTROL+L]]></description>
		<content:encoded><![CDATA[<p>In the Query Analyser PRESS CONTROL+L</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Madhivanan</title>
		<link>http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/#comment-62926</link>
		<dc:creator><![CDATA[Madhivanan]]></dc:creator>
		<pubDate>Mon, 15 Mar 2010 07:13:23 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=519#comment-62926</guid>
		<description><![CDATA[If you used Transaction, you can rollback it
Otherwise restore the latest backup you have]]></description>
		<content:encoded><![CDATA[<p>If you used Transaction, you can rollback it<br />
Otherwise restore the latest backup you have</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rsenna</title>
		<link>http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/#comment-62675</link>
		<dc:creator><![CDATA[rsenna]]></dc:creator>
		<pubDate>Wed, 10 Mar 2010 19:45:46 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=519#comment-62675</guid>
		<description><![CDATA[@Dan

I still believe Greg Jorgensen was right on that one.

To be sure that a value DOESN&#039;T exist, the engine must do a full scan. To be sure that a value exists, finding the first is enough. And if there is proper index, the scan will use it.

So, if you execute a WHERE X = 2 on a table completely filled of 1&#039;s, a full scan will happen either way - doesn&#039;t matter if you were using a EXISTS or a NOT EXISTS. The engine should work exactly the same way in both cases.]]></description>
		<content:encoded><![CDATA[<p>@Dan</p>
<p>I still believe Greg Jorgensen was right on that one.</p>
<p>To be sure that a value DOESN&#8217;T exist, the engine must do a full scan. To be sure that a value exists, finding the first is enough. And if there is proper index, the scan will use it.</p>
<p>So, if you execute a WHERE X = 2 on a table completely filled of 1&#8242;s, a full scan will happen either way &#8211; doesn&#8217;t matter if you were using a EXISTS or a NOT EXISTS. The engine should work exactly the same way in both cases.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/#comment-61612</link>
		<dc:creator><![CDATA[Dan]]></dc:creator>
		<pubDate>Tue, 23 Feb 2010 03:16:12 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=519#comment-61612</guid>
		<description><![CDATA[Greg Jorgensen said:

&quot;EXISTS and NOT EXISTS do the same work&quot;

This is not necessarily true.  Depending on the indexes being used (or not used), an EXISTS may be faster, because it can stop as soon as it finds one matching row.  A NOT EXISTS may have to table scan the entire table (if there&#039;s no index that helps the query).]]></description>
		<content:encoded><![CDATA[<p>Greg Jorgensen said:</p>
<p>&#8220;EXISTS and NOT EXISTS do the same work&#8221;</p>
<p>This is not necessarily true.  Depending on the indexes being used (or not used), an EXISTS may be faster, because it can stop as soon as it finds one matching row.  A NOT EXISTS may have to table scan the entire table (if there&#8217;s no index that helps the query).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Madhivanan</title>
		<link>http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/#comment-61423</link>
		<dc:creator><![CDATA[Madhivanan]]></dc:creator>
		<pubDate>Thu, 18 Feb 2010 13:10:12 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=519#comment-61423</guid>
		<description><![CDATA[Siva,

You need to have a valid backup in advance or you may need some third party tools]]></description>
		<content:encoded><![CDATA[<p>Siva,</p>
<p>You need to have a valid backup in advance or you may need some third party tools</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: siva</title>
		<link>http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/#comment-56756</link>
		<dc:creator><![CDATA[siva]]></dc:creator>
		<pubDate>Fri, 16 Oct 2009 13:44:46 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=519#comment-56756</guid>
		<description><![CDATA[How do we get back the data that we have deleted from a table?]]></description>
		<content:encoded><![CDATA[<p>How do we get back the data that we have deleted from a table?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason Short</title>
		<link>http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/#comment-53968</link>
		<dc:creator><![CDATA[Jason Short]]></dc:creator>
		<pubDate>Wed, 22 Jul 2009 18:19:45 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=519#comment-53968</guid>
		<description><![CDATA[I would not call it a bug if they were not the same under the hood.  The optimizer can only guess so much.  It really depends on how the statements are written.  The ones above are pretty simple and should optimize well, but not all are that easily second guessed as to their intent.]]></description>
		<content:encoded><![CDATA[<p>I would not call it a bug if they were not the same under the hood.  The optimizer can only guess so much.  It really depends on how the statements are written.  The ones above are pretty simple and should optimize well, but not all are that easily second guessed as to their intent.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Evan Carroll</title>
		<link>http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/#comment-53884</link>
		<dc:creator><![CDATA[Evan Carroll]]></dc:creator>
		<pubDate>Mon, 20 Jul 2009 15:23:46 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=519#comment-53884</guid>
		<description><![CDATA[I would call it a fairly major bug in the query engine if SELECT 1, and SELECT * were not optimized to do the same thing when the context is within the EXIST() statement. Certainly, there is no practical reason why you would visit any extra meta data at all if exists is just going to return a SQL bool..]]></description>
		<content:encoded><![CDATA[<p>I would call it a fairly major bug in the query engine if SELECT 1, and SELECT * were not optimized to do the same thing when the context is within the EXIST() statement. Certainly, there is no practical reason why you would visit any extra meta data at all if exists is just going to return a SQL bool..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sangam Uprety</title>
		<link>http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/#comment-53865</link>
		<dc:creator><![CDATA[Sangam Uprety]]></dc:creator>
		<pubDate>Mon, 20 Jul 2009 09:43:21 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=519#comment-53865</guid>
		<description><![CDATA[Simple issue and much discussions. And good one! Since in much cases we have to execute the EXISTS, using faster one [may be only fractions of second faster] matters. My preference is using SELECT 1, however. Thanks.]]></description>
		<content:encoded><![CDATA[<p>Simple issue and much discussions. And good one! Since in much cases we have to execute the EXISTS, using faster one [may be only fractions of second faster] matters. My preference is using SELECT 1, however. Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Greg Jorgensen</title>
		<link>http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/#comment-53844</link>
		<dc:creator><![CDATA[Greg Jorgensen]]></dc:creator>
		<pubDate>Sun, 19 Jul 2009 20:36:10 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=519#comment-53844</guid>
		<description><![CDATA[Lutz:

EXISTS and NOT EXISTS do the same work: the db engine only has to find a single row that matches the WHERE clause in the subquery to satisfy the test. The syntax gives it aways: NOT EXISTS is the logical NOT of the EXISTS test.

Depending on the subquery WHERE condition the existence of at least one matching row may be answered by scanning an index, or it may require a table scan. In either case as soon as a single matching row is found the result of EXISTS is known. The result of NOT EXISTS is simply the logical inverse of the result of EXISTS.

In your example the subquery inside the EXISTS() doesn&#039;t &quot;return approx. 1 million rows.&quot; It doesn&#039;t return any rows -- it returns a TRUE or FALSE. The db engine can give the result when it encounters the first row matching the WHERE clause. There is no result set to discard for the subquery.

If you are seeing different results using SELECT 1 vs. SELECT * it&#039;s probably due to SELECT * having done all the work and cached the indexes so SELECT 1 has less work to do.]]></description>
		<content:encoded><![CDATA[<p>Lutz:</p>
<p>EXISTS and NOT EXISTS do the same work: the db engine only has to find a single row that matches the WHERE clause in the subquery to satisfy the test. The syntax gives it aways: NOT EXISTS is the logical NOT of the EXISTS test.</p>
<p>Depending on the subquery WHERE condition the existence of at least one matching row may be answered by scanning an index, or it may require a table scan. In either case as soon as a single matching row is found the result of EXISTS is known. The result of NOT EXISTS is simply the logical inverse of the result of EXISTS.</p>
<p>In your example the subquery inside the EXISTS() doesn&#8217;t &#8220;return approx. 1 million rows.&#8221; It doesn&#8217;t return any rows &#8212; it returns a TRUE or FALSE. The db engine can give the result when it encounters the first row matching the WHERE clause. There is no result set to discard for the subquery.</p>
<p>If you are seeing different results using SELECT 1 vs. SELECT * it&#8217;s probably due to SELECT * having done all the work and cached the indexes so SELECT 1 has less work to do.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Greg Jorgensen</title>
		<link>http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/#comment-53843</link>
		<dc:creator><![CDATA[Greg Jorgensen]]></dc:creator>
		<pubDate>Sun, 19 Jul 2009 20:26:21 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=519#comment-53843</guid>
		<description><![CDATA[This shouldn&#039;t be such a mysterious of contentious subject. SELECT * in an EXISTS condition is a SQL idiom. In this context * means &quot;I don&#039;t care about the columns,&quot; not &quot;fetch all columns.&quot; It may or may not be optimized by the compiler depending on the dialect of SQL. Apparently T-SQL is smart in this regard but other RDBMSs may special-case SELECT * in subqueries.

The Microsoft SQL Server documentation says this:

&quot;The select list of a subquery introduced with EXISTS, by convention, has an asterisk (*) instead of a single column name. The rules for a subquery introduced with EXISTS are the same as those for a standard select list, because a subquery introduced with EXISTS creates an existence test and returns TRUE or FALSE, instead of data.&quot; (T-SQL reference, Subquery Rules).

Anyone who knows SQL should recognize the idiom EXISTS(SELECT * ...). The alternative EXISTS(SELECT 1 ...) is obvious but not really idiomatic. Anything else is just showing off and making the SQL harder for the next person to understand.]]></description>
		<content:encoded><![CDATA[<p>This shouldn&#8217;t be such a mysterious of contentious subject. SELECT * in an EXISTS condition is a SQL idiom. In this context * means &#8220;I don&#8217;t care about the columns,&#8221; not &#8220;fetch all columns.&#8221; It may or may not be optimized by the compiler depending on the dialect of SQL. Apparently T-SQL is smart in this regard but other RDBMSs may special-case SELECT * in subqueries.</p>
<p>The Microsoft SQL Server documentation says this:</p>
<p>&#8220;The select list of a subquery introduced with EXISTS, by convention, has an asterisk (*) instead of a single column name. The rules for a subquery introduced with EXISTS are the same as those for a standard select list, because a subquery introduced with EXISTS creates an existence test and returns TRUE or FALSE, instead of data.&#8221; (T-SQL reference, Subquery Rules).</p>
<p>Anyone who knows SQL should recognize the idiom EXISTS(SELECT * &#8230;). The alternative EXISTS(SELECT 1 &#8230;) is obvious but not really idiomatic. Anything else is just showing off and making the SQL harder for the next person to understand.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER - Guidelines and Coding Standards Part - 1 Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/#comment-47500</link>
		<dc:creator><![CDATA[SQL SERVER - Guidelines and Coding Standards Part - 1 Journey to SQL Authority with Pinal Dave]]></dc:creator>
		<pubDate>Thu, 26 Feb 2009 12:13:52 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=519#comment-47500</guid>
		<description><![CDATA[[...] Indent code for better readability. (Example) [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Indent code for better readability. (Example) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Palanisamy</title>
		<link>http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/#comment-46444</link>
		<dc:creator><![CDATA[Palanisamy]]></dc:creator>
		<pubDate>Sun, 08 Feb 2009 06:57:29 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=519#comment-46444</guid>
		<description><![CDATA[Hi Pinal,
            How can we see the &quot;excution Plan&quot;????

Regards,
Palanisamy]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,<br />
            How can we see the &#8220;excution Plan&#8221;????</p>
<p>Regards,<br />
Palanisamy</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rohit</title>
		<link>http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/#comment-46427</link>
		<dc:creator><![CDATA[rohit]]></dc:creator>
		<pubDate>Sat, 07 Feb 2009 13:37:40 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=519#comment-46427</guid>
		<description><![CDATA[how do we get back the data that we ve deleted from a table??]]></description>
		<content:encoded><![CDATA[<p>how do we get back the data that we ve deleted from a table??</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rao K</title>
		<link>http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/#comment-44561</link>
		<dc:creator><![CDATA[Rao K]]></dc:creator>
		<pubDate>Fri, 05 Dec 2008 17:39:42 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=519#comment-44561</guid>
		<description><![CDATA[What is the equallent in SQL Server for 

select * from table1 a
where (a.x, a.y) in (
select b.x, min(b.y)
from table1 b
group by b.x
)]]></description>
		<content:encoded><![CDATA[<p>What is the equallent in SQL Server for </p>
<p>select * from table1 a<br />
where (a.x, a.y) in (<br />
select b.x, min(b.y)<br />
from table1 b<br />
group by b.x<br />
)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lutz Mueller</title>
		<link>http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/#comment-44337</link>
		<dc:creator><![CDATA[Lutz Mueller]]></dc:creator>
		<pubDate>Fri, 21 Nov 2008 15:24:48 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=519#comment-44337</guid>
		<description><![CDATA[Hi Pinal,

I&#039;m wondering what test conditions you used...

The other day I had a performance issue with a proceudre that included a statement like

IF NOT EXISTS (SELECT * FROM view WHERE condition)

The view itself based on two tables withe several 10-thousand rows in one and several million in the other (as to my best knowledge properly joined and indexed using information from STATISTICS XML). The SELECT statement above would return approx. 1 million rows.

When I changed it to SELECT 1, performance increased significantly.

My explanation (at least to myself) goes a little more in direction of boolean logic:

The NOT EXISTS statement becomes FALSE performing the following tasks:
SELECT * -&gt; grab all the data and if there are any drop them and return FALSE
SELECT 1 -&gt; try to grab the first row and if you find one single row return FALSE, no matter on how many rows fulfill the WHERE clause

As far as I figured the TRUE statement takes the same time for both, * amd 1, since the resultset is NULL in both cases.

Would you agree with my comment and, if not, retest your code with large tables?

Regards

Lutz]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>I&#8217;m wondering what test conditions you used&#8230;</p>
<p>The other day I had a performance issue with a proceudre that included a statement like</p>
<p>IF NOT EXISTS (SELECT * FROM view WHERE condition)</p>
<p>The view itself based on two tables withe several 10-thousand rows in one and several million in the other (as to my best knowledge properly joined and indexed using information from STATISTICS XML). The SELECT statement above would return approx. 1 million rows.</p>
<p>When I changed it to SELECT 1, performance increased significantly.</p>
<p>My explanation (at least to myself) goes a little more in direction of boolean logic:</p>
<p>The NOT EXISTS statement becomes FALSE performing the following tasks:<br />
SELECT * -&gt; grab all the data and if there are any drop them and return FALSE<br />
SELECT 1 -&gt; try to grab the first row and if you find one single row return FALSE, no matter on how many rows fulfill the WHERE clause</p>
<p>As far as I figured the TRUE statement takes the same time for both, * amd 1, since the resultset is NULL in both cases.</p>
<p>Would you agree with my comment and, if not, retest your code with large tables?</p>
<p>Regards</p>
<p>Lutz</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Stauffer</title>
		<link>http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/#comment-43000</link>
		<dc:creator><![CDATA[Bryan Stauffer]]></dc:creator>
		<pubDate>Fri, 19 Sep 2008 17:49:15 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=519#comment-43000</guid>
		<description><![CDATA[sorry, on that last post, i tried to include a string that inadvertenly looked like html and was stripped out.  just use any user-defined table for the [name] = portion of the query to duplicate my findings.]]></description>
		<content:encoded><![CDATA[<p>sorry, on that last post, i tried to include a string that inadvertenly looked like html and was stripped out.  just use any user-defined table for the [name] = portion of the query to duplicate my findings.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Stauffer</title>
		<link>http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/#comment-42999</link>
		<dc:creator><![CDATA[Bryan Stauffer]]></dc:creator>
		<pubDate>Fri, 19 Sep 2008 17:47:31 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=519#comment-42999</guid>
		<description><![CDATA[SQL 2005

I managed to get a glimpse using the following two queries.  According the estimated query execution plans the &#039;select *&#039; query has an extra step and the estimated row size is larger than &#039;select 1&#039;.  Perhaps this is not proof but I think it is more evidence that &#039;select 1&#039; is the better practice.

select * from tempdb.sys.sysobjects where [name] = &#039;&#039;

select 1 from tempdb.sys.sysobjects where [name] = &#039;&#039;]]></description>
		<content:encoded><![CDATA[<p>SQL 2005</p>
<p>I managed to get a glimpse using the following two queries.  According the estimated query execution plans the &#8216;select *&#8217; query has an extra step and the estimated row size is larger than &#8216;select 1&#8242;.  Perhaps this is not proof but I think it is more evidence that &#8216;select 1&#8242; is the better practice.</p>
<p>select * from tempdb.sys.sysobjects where [name] = &#8221;</p>
<p>select 1 from tempdb.sys.sysobjects where [name] = &#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: G2</title>
		<link>http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/#comment-40043</link>
		<dc:creator><![CDATA[G2]]></dc:creator>
		<pubDate>Thu, 10 Jul 2008 20:22:47 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=519#comment-40043</guid>
		<description><![CDATA[Nice observation]]></description>
		<content:encoded><![CDATA[<p>Nice observation</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ravi</title>
		<link>http://blog.sqlauthority.com/2008/02/26/sql-server-select-1-vs-select-an-interesting-observation/#comment-39486</link>
		<dc:creator><![CDATA[Ravi]]></dc:creator>
		<pubDate>Wed, 25 Jun 2008 06:39:53 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=519#comment-39486</guid>
		<description><![CDATA[Hi emily here is the answer for your question.

SELECT rnum, employee_id
FROM (
   SELECT rownum rnum, employee_id
   FROM employees
   WHERE ROWNUM &lt; 100)
WHERE rnum BETWEEN 2 AND 12;

this query will retrieve output for 
record 2 until record 12. By use of inline view.

Regards,
Ravi 
Sony India
____________________
Hi,

Just want to ask, is there any select statement whereby it will call you to select the record start from second record then additional 10 records onwards?

For example,

User have to retrieve record 2 until record 12?
If yes, can help?

Thanks.]]></description>
		<content:encoded><![CDATA[<p>Hi emily here is the answer for your question.</p>
<p>SELECT rnum, employee_id<br />
FROM (<br />
   SELECT rownum rnum, employee_id<br />
   FROM employees<br />
   WHERE ROWNUM &lt; 100)<br />
WHERE rnum BETWEEN 2 AND 12;</p>
<p>this query will retrieve output for<br />
record 2 until record 12. By use of inline view.</p>
<p>Regards,<br />
Ravi<br />
Sony India<br />
____________________<br />
Hi,</p>
<p>Just want to ask, is there any select statement whereby it will call you to select the record start from second record then additional 10 records onwards?</p>
<p>For example,</p>
<p>User have to retrieve record 2 until record 12?<br />
If yes, can help?</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

