 




<?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: Complex sort for SQL Query?</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/complex-sort-for-sql-query/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/complex-sort-for-sql-query/</link>
	<description></description>
	<lastBuildDate>Wed, 22 May 2013 18:27:48 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: TomLiotta</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/complex-sort-for-sql-query/#comment-112139</link>
		<dc:creator>TomLiotta</dc:creator>
		<pubDate>Wed, 10 Oct 2012 23:15:13 +0000</pubDate>
		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/itanswers/complex-sort-for-sql-query/#comment-112139</guid>
		<description><![CDATA[I&#039;m thinking maybe the OP confused terms. Hard to tell without a response. -- Tom]]></description>
		<content:encoded><![CDATA[<p>I&#8217;m thinking maybe the OP confused terms. Hard to tell without a response. &#8212; Tom</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: carlosdl</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/complex-sort-for-sql-query/#comment-112138</link>
		<dc:creator>carlosdl</dc:creator>
		<pubDate>Wed, 10 Oct 2012 23:08:16 +0000</pubDate>
		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/itanswers/complex-sort-for-sql-query/#comment-112138</guid>
		<description><![CDATA[Oh, I just realised that maybe I&#039;m confusing terms. That one&#160;is not the oldest, but the newest date.]]></description>
		<content:encoded><![CDATA[<p>Oh, I just realised that maybe I&#8217;m confusing terms. That one&nbsp;is not the oldest, but the newest date.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: carlosdl</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/complex-sort-for-sql-query/#comment-112137</link>
		<dc:creator>carlosdl</dc:creator>
		<pubDate>Wed, 10 Oct 2012 23:03:38 +0000</pubDate>
		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/itanswers/complex-sort-for-sql-query/#comment-112137</guid>
		<description><![CDATA[This would be the record with the oldest date (Name4, 2, 9/3/2012), and I think the format being used is d/m/yyyy.&#160;

The text formatting in the question doesn&#039;t help much.&#160;&#160;]]></description>
		<content:encoded><![CDATA[<p>This would be the record with the oldest date (Name4, 2, 9/3/2012), and I think the format being used is d/m/yyyy.&nbsp;</p>
<p>The text formatting in the question doesn&#8217;t help much.&nbsp;&nbsp;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: TomLiotta</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/complex-sort-for-sql-query/#comment-112134</link>
		<dc:creator>TomLiotta</dc:creator>
		<pubDate>Wed, 10 Oct 2012 22:11:01 +0000</pubDate>
		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/itanswers/complex-sort-for-sql-query/#comment-112134</guid>
		<description><![CDATA[&lt;EM&gt;Actually, the oldest date is in the first group, which happens to be for the identifier ’2′.&lt;/EM&gt;
&#160;
What am I missing? The oldest date I can see is &quot;1/2/2012&quot;, for identifier &#039;3&#039;, which should be either 1 Feb 2012 or Jan 2 2012. The oldest date for identifier &#039;2&#039; is &quot;1/3/2012&quot;. Whichever date format is used, &quot;1/2/2012&quot; is&#160; an earlier (oldest)&#160;date. Isn&#039;t it? (Maybe I&#039;m too tired lately.)
&#160;
Tom]]></description>
		<content:encoded><![CDATA[<p><em>Actually, the oldest date is in the first group, which happens to be for the identifier ’2′.</em><br />
&nbsp;<br />
What am I missing? The oldest date I can see is &#8220;1/2/2012&#8243;, for identifier &#8217;3&#8242;, which should be either 1 Feb 2012 or Jan 2 2012. The oldest date for identifier &#8217;2&#8242; is &#8220;1/3/2012&#8243;. Whichever date format is used, &#8220;1/2/2012&#8243; is&nbsp; an earlier (oldest)&nbsp;date. Isn&#8217;t it? (Maybe I&#8217;m too tired lately.)<br />
&nbsp;<br />
Tom</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: carlosdl</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/complex-sort-for-sql-query/#comment-112133</link>
		<dc:creator>carlosdl</dc:creator>
		<pubDate>Wed, 10 Oct 2012 21:50:06 +0000</pubDate>
		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/itanswers/complex-sort-for-sql-query/#comment-112133</guid>
		<description><![CDATA[And the simplest one, using an analytic MAX:

SELECT name,identifier,&quot;DATE&quot;,MAX(&quot;DATE&quot;) OVER (PARTITION BY identifier) md
FROM your_table
ORDER BY md DESC,identifier,&quot;DATE&quot;;&#160;

;-)]]></description>
		<content:encoded><![CDATA[<p>And the simplest one, using an analytic MAX:</p>
<p>SELECT name,identifier,&#8221;DATE&#8221;,MAX(&#8220;DATE&#8221;) OVER (PARTITION BY identifier) md<br />
FROM your_table<br />
ORDER BY md DESC,identifier,&#8221;DATE&#8221;;&nbsp;</p>
<p> <img src='http://itknowledgeexchange.techtarget.com/itanswers/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: carlosdl</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/complex-sort-for-sql-query/#comment-112131</link>
		<dc:creator>carlosdl</dc:creator>
		<pubDate>Wed, 10 Oct 2012 21:26:37 +0000</pubDate>
		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/itanswers/complex-sort-for-sql-query/#comment-112131</guid>
		<description><![CDATA[On recent Oracle versions, this should also work:

WITH t AS (
SELECT identifier,max(&quot;DATE&quot;) max_date  
  FROM your_table GROUP BY identifier
)
SELECT yt.name,yt.identifier,yt.&quot;DATE&quot; 
FROM your_table yt JOIN t
  on yt.identifier=t.identifier
ORDER BY t.max_date DESC,yt.identifier,yt.&quot;DATE&quot;;]]></description>
		<content:encoded><![CDATA[<p>On recent Oracle versions, this should also work:</p>
<p>WITH t AS (<br />
SELECT identifier,max(&#8220;DATE&#8221;) max_date<br />
  FROM your_table GROUP BY identifier<br />
)<br />
SELECT yt.name,yt.identifier,yt.&#8221;DATE&#8221;<br />
FROM your_table yt JOIN t<br />
  on yt.identifier=t.identifier<br />
ORDER BY t.max_date DESC,yt.identifier,yt.&#8221;DATE&#8221;;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: carlosdl</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/complex-sort-for-sql-query/#comment-112130</link>
		<dc:creator>carlosdl</dc:creator>
		<pubDate>Wed, 10 Oct 2012 21:20:05 +0000</pubDate>
		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/itanswers/complex-sort-for-sql-query/#comment-112130</guid>
		<description><![CDATA[&quot;...&lt;em&gt;dates are ordered; but the ‘oldest’ date isn’t in the first group — it’s in the second group&lt;/em&gt;&quot;&#160;

Actually, the oldest date is in the first group, which happens to be for the identifier &#039;2&#039;.&#160;

If I understand correctly, something like this should do the trick:

SELECT name,identifier,&quot;DATE&quot;,(select MAX(&quot;DATE&quot;) FROM your_table WHERE identifier = yt.identifier)
from your_table yt
ORDER BY 4 desc,2,3;&#160;

&#160;I think something like this is what Todd was suggesting too.&#160;]]></description>
		<content:encoded><![CDATA[<p>&#8220;&#8230;<em>dates are ordered; but the ‘oldest’ date isn’t in the first group — it’s in the second group</em>&#8220;&nbsp;</p>
<p>Actually, the oldest date is in the first group, which happens to be for the identifier &#8217;2&#8242;.&nbsp;</p>
<p>If I understand correctly, something like this should do the trick:</p>
<p>SELECT name,identifier,&#8221;DATE&#8221;,(select MAX(&#8220;DATE&#8221;) FROM your_table WHERE identifier = yt.identifier)<br />
from your_table yt<br />
ORDER BY 4 desc,2,3;&nbsp;</p>
<p>&nbsp;I think something like this is what Todd was suggesting too.&nbsp;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ToddN2000</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/complex-sort-for-sql-query/#comment-112123</link>
		<dc:creator>ToddN2000</dc:creator>
		<pubDate>Wed, 10 Oct 2012 20:07:14 +0000</pubDate>
		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/itanswers/complex-sort-for-sql-query/#comment-112123</guid>
		<description><![CDATA[If I understand how you are looking to sort this, I don&#039;t think you can do it with one table. It sounds like you want them sorted by date to find the order for your groups then sort all related group detail data by date within that group. You might try and create an alias table that is a summary of groups in date order. Then use this table in group/date order to get the full detail in date sequence.]]></description>
		<content:encoded><![CDATA[<p>If I understand how you are looking to sort this, I don&#8217;t think you can do it with one table. It sounds like you want them sorted by date to find the order for your groups then sort all related group detail data by date within that group. You might try and create an alias table that is a summary of groups in date order. Then use this table in group/date order to get the full detail in date sequence.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: TomLiotta</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/complex-sort-for-sql-query/#comment-112075</link>
		<dc:creator>TomLiotta</dc:creator>
		<pubDate>Tue, 09 Oct 2012 23:21:15 +0000</pubDate>
		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/itanswers/complex-sort-for-sql-query/#comment-112075</guid>
		<description><![CDATA[What does the &quot;identifier&quot; identify? It doesn&#039;t seem to identify a name nor a date. It would seem to be an &quot;identifier&quot; for some entity that is defined in a different table.
&#160;
Your &quot;example&quot; of how you want it to work doesn&#039;t seem to have any identifiable sequence. It does seem to be &#039;grouped by&#039; the &quot;identifier&quot; but the &quot;identifier&quot; has no meaningful ordering. Within each group, dates are ordered; but the &#039;oldest&#039; date isn&#039;t in the first group -- it&#039;s in the second group.
&#160;
More info is needed about how you want this to work. Perhaps an entirely new set of example values might even be helpful.
&#160;
Tom]]></description>
		<content:encoded><![CDATA[<p>What does the &#8220;identifier&#8221; identify? It doesn&#8217;t seem to identify a name nor a date. It would seem to be an &#8220;identifier&#8221; for some entity that is defined in a different table.<br />
&nbsp;<br />
Your &#8220;example&#8221; of how you want it to work doesn&#8217;t seem to have any identifiable sequence. It does seem to be &#8216;grouped by&#8217; the &#8220;identifier&#8221; but the &#8220;identifier&#8221; has no meaningful ordering. Within each group, dates are ordered; but the &#8216;oldest&#8217; date isn&#8217;t in the first group &#8212; it&#8217;s in the second group.<br />
&nbsp;<br />
More info is needed about how you want this to work. Perhaps an entirely new set of example values might even be helpful.<br />
&nbsp;<br />
Tom</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 6/8 queries in 0.013 seconds using memcached
Object Caching 385/386 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-05-22 23:16:38 -->