<?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: MySQL GROUP BY and DISTINCT Oddity</title>
	<atom:link href="http://www.pythian.com/news/374/mysql-group-by-and-distinct-oddity/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pythian.com/news/374/mysql-group-by-and-distinct-oddity/</link>
	<description>News and views from Pythian DBAs</description>
	<lastBuildDate>Fri, 10 Feb 2012 13:01:25 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
	<item>
		<title>By: Alex Gorbachev</title>
		<link>http://www.pythian.com/news/374/mysql-group-by-and-distinct-oddity/#comment-16199</link>
		<dc:creator>Alex Gorbachev</dc:creator>
		<pubDate>Mon, 22 Jan 2007 14:21:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.pythian.com/blogs/374/mysql-group-by-and-distinct-oddity#comment-16199</guid>
		<description>Explanation is simple. Oracle isn&#039;t smart but just follows the rules. The rule in this case - expression in order by must consist of selected columns/expressions. This should work I believe:
&lt;code&gt;
select distinct substr(privilege,1,2)
  from user_tab_privs_recd
  order by substr(substr(privilege,1,2),1,1)
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Explanation is simple. Oracle isn&#8217;t smart but just follows the rules. The rule in this case &#8211; expression in order by must consist of selected columns/expressions. This should work I believe:<br />
<code><br />
select distinct substr(privilege,1,2)<br />
  from user_tab_privs_recd<br />
  order by substr(substr(privilege,1,2),1,1)<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gary</title>
		<link>http://www.pythian.com/news/374/mysql-group-by-and-distinct-oddity/#comment-16110</link>
		<dc:creator>Gary</dc:creator>
		<pubDate>Mon, 22 Jan 2007 04:00:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.pythian.com/blogs/374/mysql-group-by-and-distinct-oddity#comment-16110</guid>
		<description>Whoops. Meant to say
THIS one works:
select distinct privilege from user_tab_privs_recd order by substr(privilege,1,3);
This one doesn&#039;t
select distinct substr(privilege,1,2) from user_tab_privs_recd 
order by substr(privilege,1,1)
so there are limits to its smarts.</description>
		<content:encoded><![CDATA[<p>Whoops. Meant to say<br />
THIS one works:<br />
select distinct privilege from user_tab_privs_recd order by substr(privilege,1,3);<br />
This one doesn&#8217;t<br />
select distinct substr(privilege,1,2) from user_tab_privs_recd<br />
order by substr(privilege,1,1)<br />
so there are limits to its smarts.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gary</title>
		<link>http://www.pythian.com/news/374/mysql-group-by-and-distinct-oddity/#comment-16109</link>
		<dc:creator>Gary</dc:creator>
		<pubDate>Mon, 22 Jan 2007 03:58:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.pythian.com/blogs/374/mysql-group-by-and-distinct-oddity#comment-16109</guid>
		<description>Interestingly, Oracle applies some smarts too.
The following works fine:
select distinct substr(privilege,1,2) from user_tab_privs_recd 
order by substr(privilege,1,2);
but this fails:
select distinct substr(privilege,1,2) from user_tab_privs_recd 
order by substr(privilege,1,3);
Oracle actually works out whether it can derive the order by expression from the selected expression, rather than simply ruling out anything that isn&#039;t actually selected.</description>
		<content:encoded><![CDATA[<p>Interestingly, Oracle applies some smarts too.<br />
The following works fine:<br />
select distinct substr(privilege,1,2) from user_tab_privs_recd<br />
order by substr(privilege,1,2);<br />
but this fails:<br />
select distinct substr(privilege,1,2) from user_tab_privs_recd<br />
order by substr(privilege,1,3);<br />
Oracle actually works out whether it can derive the order by expression from the selected expression, rather than simply ruling out anything that isn&#8217;t actually selected.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

