<?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/"
		>
<channel>
	<title>Comments on: &#8220;SELECT DISTINCT &#8230; ORDER BY&#8221; is broken in Sybase ASE 12.5.3</title>
	<atom:link href="http://dossy.org/2006/05/select-distinct-order-by-is-broken-in-sybase-ase-1253/feed/" rel="self" type="application/rss+xml" />
	<link>http://dossy.org/2006/05/select-distinct-order-by-is-broken-in-sybase-ase-1253/</link>
	<description>Everything that comes out of Dossy, from the strange to the banal.</description>
	<lastBuildDate>Fri, 20 Nov 2009 01:35:37 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: RoyceB</title>
		<link>http://dossy.org/2006/05/select-distinct-order-by-is-broken-in-sybase-ase-1253/comment-page-1/#comment-395</link>
		<dc:creator>RoyceB</dc:creator>
		<pubDate>Tue, 23 May 2006 23:23:38 +0000</pubDate>
		<guid isPermaLink="false">http://dossy.org/archives/000276.html#comment-395</guid>
		<description>The ASE Transact-SQL User&#039;s Guide addresses this on page 105 of the 12.5.1 edition.

&quot;If a query has an &#039;order by&#039; or &#039;group by&#039; clause that includes columns not in the select list, Adaptive Server adds those columns as hidden columns in the columns being processed. The columns listed in the &#039;order by&#039; or &#039;group by&#039; clause are included in the test for distinct rows. To comply with ANSI standards, include the &#039;order by&#039; or &#039;group by&#039; column in the select list.&quot;</description>
		<content:encoded><![CDATA[<p>The ASE Transact-SQL User&#8217;s Guide addresses this on page 105 of the 12.5.1 edition.</p>
<p>&#8220;If a query has an &#8216;order by&#8217; or &#8216;group by&#8217; clause that includes columns not in the select list, Adaptive Server adds those columns as hidden columns in the columns being processed. The columns listed in the &#8216;order by&#8217; or &#8216;group by&#8217; clause are included in the test for distinct rows. To comply with ANSI standards, include the &#8216;order by&#8217; or &#8216;group by&#8217; column in the select list.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dossy</title>
		<link>http://dossy.org/2006/05/select-distinct-order-by-is-broken-in-sybase-ase-1253/comment-page-1/#comment-394</link>
		<dc:creator>Dossy</dc:creator>
		<pubDate>Wed, 03 May 2006 18:07:06 +0000</pubDate>
		<guid isPermaLink="false">http://dossy.org/archives/000276.html#comment-394</guid>
		<description>Steve:

Interestingly, MySQL 4.1.11 handles this &quot;correctly&quot; as I would have expected:

&lt;pre&gt;mysql&gt; SELECT DISTINCT x FROM test ORDER BY y DESC;
+------+
&#124; x    &#124;
+------+
&#124;    3 &#124;
&#124;    1 &#124;
&#124;    2 &#124;
+------+
3 rows in set (0.00 sec)&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Steve:</p>
<p>Interestingly, MySQL 4.1.11 handles this &#8220;correctly&#8221; as I would have expected:</p>
<pre>mysql> SELECT DISTINCT x FROM test ORDER BY y DESC;
+------+
| x    |
+------+
|    3 |
|    1 |
|    2 |
+------+
3 rows in set (0.00 sec)</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: jh</title>
		<link>http://dossy.org/2006/05/select-distinct-order-by-is-broken-in-sybase-ase-1253/comment-page-1/#comment-393</link>
		<dc:creator>jh</dc:creator>
		<pubDate>Wed, 03 May 2006 17:05:18 +0000</pubDate>
		<guid isPermaLink="false">http://dossy.org/archives/000276.html#comment-393</guid>
		<description>SQL can be ambiguous, and this is one of those situations.  PostgreSQL mandates an ORDER BY or GROUP BY in DISTINCT-styled queries.
&lt;pre&gt;
havard=# SELECT distinct a from test order by b desc;
ERROR:  for SELECT DISTINCT, ORDER BY expressions must appear in select list
jhavard=# SELECT distinct on (a) a from test order by b desc;
ERROR:  SELECT DISTINCT ON expressions must match initial ORDER BY expressions
&lt;/pre&gt;

Take a look at the query optimizer and query planner output if possible.  I&#039;m willing to bet the query is executed as if it were &lt;tt&gt;SELECT DISTINCT ON (b) a FROM test ORDER BY b&lt;/tt&gt;.  After all, you are supplying an ordered field.</description>
		<content:encoded><![CDATA[<p>SQL can be ambiguous, and this is one of those situations.  PostgreSQL mandates an ORDER BY or GROUP BY in DISTINCT-styled queries.</p>
<pre>
havard=# SELECT distinct a from test order by b desc;
ERROR:  for SELECT DISTINCT, ORDER BY expressions must appear in select list
jhavard=# SELECT distinct on (a) a from test order by b desc;
ERROR:  SELECT DISTINCT ON expressions must match initial ORDER BY expressions
</pre>
<p>Take a look at the query optimizer and query planner output if possible.  I&#8217;m willing to bet the query is executed as if it were <tt>SELECT DISTINCT ON (b) a FROM test ORDER BY b</tt>.  After all, you are supplying an ordered field.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sgoguen</title>
		<link>http://dossy.org/2006/05/select-distinct-order-by-is-broken-in-sybase-ase-1253/comment-page-1/#comment-392</link>
		<dc:creator>sgoguen</dc:creator>
		<pubDate>Wed, 03 May 2006 16:33:07 +0000</pubDate>
		<guid isPermaLink="false">http://dossy.org/archives/000276.html#comment-392</guid>
		<description>I tried reproducing this on SQL Server 2000 and SQL Server won&#039;t even allow you to do that type of DISTINCT/ORDER BY mix.  I got the following error:

ORDER BY items must appear in the select list if SELECT DISTINCT is specified.

Clearly, there is something with this type of mix that Sybase didn&#039;t handle properly if Microsoft disabled ordering by columns that did not appear in a distinct resultset.</description>
		<content:encoded><![CDATA[<p>I tried reproducing this on SQL Server 2000 and SQL Server won&#8217;t even allow you to do that type of DISTINCT/ORDER BY mix.  I got the following error:</p>
<p>ORDER BY items must appear in the select list if SELECT DISTINCT is specified.</p>
<p>Clearly, there is something with this type of mix that Sybase didn&#8217;t handle properly if Microsoft disabled ordering by columns that did not appear in a distinct resultset.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.622 seconds -->
