<?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; UNION ALL and ORDER BY &#8211; How to Order Table Separately While Using UNION ALL</title>
	<atom:link href="http://blog.sqlauthority.com/2012/10/30/sql-server-union-all-and-order-by-how-to-order-table-separately-while-using-union-all/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2012/10/30/sql-server-union-all-and-order-by-how-to-order-table-separately-while-using-union-all/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Wed, 22 May 2013 19:03:49 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: SQL SERVER &#8211; UNION ALL and UNION are Different Operation &#124; SQL Server Journey with SQL Authority</title>
		<link>http://blog.sqlauthority.com/2012/10/30/sql-server-union-all-and-order-by-how-to-order-table-separately-while-using-union-all/#comment-464066</link>
		<dc:creator><![CDATA[SQL SERVER &#8211; UNION ALL and UNION are Different Operation &#124; SQL Server Journey with SQL Authority]]></dc:creator>
		<pubDate>Fri, 26 Apr 2013 01:30:52 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21357#comment-464066</guid>
		<description><![CDATA[[...] UNION ALL and ORDER BY – How to Order Table Separately While Using UNION ALL [...]]]></description>
		<content:encoded><![CDATA[<p>[...] UNION ALL and ORDER BY – How to Order Table Separately While Using UNION ALL [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vishwanath</title>
		<link>http://blog.sqlauthority.com/2012/10/30/sql-server-union-all-and-order-by-how-to-order-table-separately-while-using-union-all/#comment-461354</link>
		<dc:creator><![CDATA[vishwanath]]></dc:creator>
		<pubDate>Mon, 22 Apr 2013 11:39:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21357#comment-461354</guid>
		<description><![CDATA[I got a lots of info 
thanks]]></description>
		<content:encoded><![CDATA[<p>I got a lots of info<br />
thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2012/10/30/sql-server-union-all-and-order-by-how-to-order-table-separately-while-using-union-all/#comment-377201</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Tue, 20 Nov 2012 06:51:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21357#comment-377201</guid>
		<description><![CDATA[Use alias name

SELECT * FROM
 (SELECT ID, Col1 FROM t1
 UNION ALL
 SELECT ID, Col1 FROM t2) as t
 ORDER BY ID]]></description>
		<content:encoded><![CDATA[<p>Use alias name</p>
<p>SELECT * FROM<br />
 (SELECT ID, Col1 FROM t1<br />
 UNION ALL<br />
 SELECT ID, Col1 FROM t2) as t<br />
 ORDER BY ID</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Firoz</title>
		<link>http://blog.sqlauthority.com/2012/10/30/sql-server-union-all-and-order-by-how-to-order-table-separately-while-using-union-all/#comment-373657</link>
		<dc:creator><![CDATA[Firoz]]></dc:creator>
		<pubDate>Tue, 13 Nov 2012 19:44:14 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21357#comment-373657</guid>
		<description><![CDATA[Whn i am trying to execute the above query getting following errors.

Msg 156, Level 15, State 1, Line 6
Incorrect syntax near the keyword &#039;ORDER&#039;.]]></description>
		<content:encoded><![CDATA[<p>Whn i am trying to execute the above query getting following errors.</p>
<p>Msg 156, Level 15, State 1, Line 6<br />
Incorrect syntax near the keyword &#8216;ORDER&#8217;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kumar Harsh</title>
		<link>http://blog.sqlauthority.com/2012/10/30/sql-server-union-all-and-order-by-how-to-order-table-separately-while-using-union-all/#comment-367575</link>
		<dc:creator><![CDATA[Kumar Harsh]]></dc:creator>
		<pubDate>Thu, 01 Nov 2012 16:58:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21357#comment-367575</guid>
		<description><![CDATA[select * from
(SELECT id,col1 FROM
(SELECT ID, Col1 FROM t1
order by ID) t11

UNION ALL

SELECT id,col1 FROM
(SELECT ID, Col1 FROM t2
order by Col1) t22)final
order by id

if seperate ordering of each sql is required plus overall.If overall is not required then remove final.]]></description>
		<content:encoded><![CDATA[<p>select * from<br />
(SELECT id,col1 FROM<br />
(SELECT ID, Col1 FROM t1<br />
order by ID) t11</p>
<p>UNION ALL</p>
<p>SELECT id,col1 FROM<br />
(SELECT ID, Col1 FROM t2<br />
order by Col1) t22)final<br />
order by id</p>
<p>if seperate ordering of each sql is required plus overall.If overall is not required then remove final.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: alb</title>
		<link>http://blog.sqlauthority.com/2012/10/30/sql-server-union-all-and-order-by-how-to-order-table-separately-while-using-union-all/#comment-367066</link>
		<dc:creator><![CDATA[alb]]></dc:creator>
		<pubDate>Wed, 31 Oct 2012 14:46:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21357#comment-367066</guid>
		<description><![CDATA[SELECT * FROM
   (SELECT ID, Col1 FROM t1 
   UNION ALL
   SELECT ID, Col1 FROM t2)
ORDER BY ID]]></description>
		<content:encoded><![CDATA[<p>SELECT * FROM<br />
   (SELECT ID, Col1 FROM t1<br />
   UNION ALL<br />
   SELECT ID, Col1 FROM t2)<br />
ORDER BY ID</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Coolmind</title>
		<link>http://blog.sqlauthority.com/2012/10/30/sql-server-union-all-and-order-by-how-to-order-table-separately-while-using-union-all/#comment-366626</link>
		<dc:creator><![CDATA[Coolmind]]></dc:creator>
		<pubDate>Tue, 30 Oct 2012 21:14:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21357#comment-366626</guid>
		<description><![CDATA[In this case, I would use CTE 

because in this last SQL Statement, it&#039;s giving one additional column as an output. If you want to keep the same output, use CTE instead. 

Thanks,]]></description>
		<content:encoded><![CDATA[<p>In this case, I would use CTE </p>
<p>because in this last SQL Statement, it&#8217;s giving one additional column as an output. If you want to keep the same output, use CTE instead. </p>
<p>Thanks,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hugo Cueva</title>
		<link>http://blog.sqlauthority.com/2012/10/30/sql-server-union-all-and-order-by-how-to-order-table-separately-while-using-union-all/#comment-366605</link>
		<dc:creator><![CDATA[Hugo Cueva]]></dc:creator>
		<pubDate>Tue, 30 Oct 2012 19:58:03 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21357#comment-366605</guid>
		<description><![CDATA[Hi, it might be easier to do the select in a subquery and the union all after?]]></description>
		<content:encoded><![CDATA[<p>Hi, it might be easier to do the select in a subquery and the union all after?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sanjay Monpara</title>
		<link>http://blog.sqlauthority.com/2012/10/30/sql-server-union-all-and-order-by-how-to-order-table-separately-while-using-union-all/#comment-366523</link>
		<dc:creator><![CDATA[Sanjay Monpara]]></dc:creator>
		<pubDate>Tue, 30 Oct 2012 14:28:05 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21357#comment-366523</guid>
		<description><![CDATA[If you want different order for both query then you can do it like this,

select * from (SELECT top 100 percent ID, Col1 FROM t1 order by id) a
UNION all
select * from (SELECT top 100 percent ID, Col1 FROM t2 order by id desc) b

ID	Col1
1	Col1-t1
2	Col2-t1
3	Col3-t1
3	Col1-t2
2	Col2-t2
1	Col3-t2]]></description>
		<content:encoded><![CDATA[<p>If you want different order for both query then you can do it like this,</p>
<p>select * from (SELECT top 100 percent ID, Col1 FROM t1 order by id) a<br />
UNION all<br />
select * from (SELECT top 100 percent ID, Col1 FROM t2 order by id desc) b</p>
<p>ID	Col1<br />
1	Col1-t1<br />
2	Col2-t1<br />
3	Col3-t1<br />
3	Col1-t2<br />
2	Col2-t2<br />
1	Col3-t2</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gp13</title>
		<link>http://blog.sqlauthority.com/2012/10/30/sql-server-union-all-and-order-by-how-to-order-table-separately-while-using-union-all/#comment-366488</link>
		<dc:creator><![CDATA[gp13]]></dc:creator>
		<pubDate>Tue, 30 Oct 2012 12:13:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21357#comment-366488</guid>
		<description><![CDATA[Need to really appreciate it...Nice Post.

Regards,
Girijesh]]></description>
		<content:encoded><![CDATA[<p>Need to really appreciate it&#8230;Nice Post.</p>
<p>Regards,<br />
Girijesh</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lakshmi Ganesh</title>
		<link>http://blog.sqlauthority.com/2012/10/30/sql-server-union-all-and-order-by-how-to-order-table-separately-while-using-union-all/#comment-366445</link>
		<dc:creator><![CDATA[Lakshmi Ganesh]]></dc:creator>
		<pubDate>Tue, 30 Oct 2012 09:33:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21357#comment-366445</guid>
		<description><![CDATA[Request you send all further notifications. Thanks]]></description>
		<content:encoded><![CDATA[<p>Request you send all further notifications. Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lakshmi Ganesh</title>
		<link>http://blog.sqlauthority.com/2012/10/30/sql-server-union-all-and-order-by-how-to-order-table-separately-while-using-union-all/#comment-366444</link>
		<dc:creator><![CDATA[Lakshmi Ganesh]]></dc:creator>
		<pubDate>Tue, 30 Oct 2012 09:32:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21357#comment-366444</guid>
		<description><![CDATA[Nice post. Please send all new tips for below mail id. Thanks in advance.]]></description>
		<content:encoded><![CDATA[<p>Nice post. Please send all new tips for below mail id. Thanks in advance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hari</title>
		<link>http://blog.sqlauthority.com/2012/10/30/sql-server-union-all-and-order-by-how-to-order-table-separately-while-using-union-all/#comment-366377</link>
		<dc:creator><![CDATA[Hari]]></dc:creator>
		<pubDate>Tue, 30 Oct 2012 03:45:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=21357#comment-366377</guid>
		<description><![CDATA[It seems like the title is wrong, you are not ordering the tables separately (which to me implies that a different order by clause is used for different tables), you are just &quot;clustering&quot; the rows from the same table together.]]></description>
		<content:encoded><![CDATA[<p>It seems like the title is wrong, you are not ordering the tables separately (which to me implies that a different order by clause is used for different tables), you are just &#8220;clustering&#8221; the rows from the same table together.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
