<?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: SELECT and WHERE, but no FROM clause	</title>
	<atom:link href="https://lobsterpot.com.au/blog/2011/04/12/select-and-where-but-no-from-clause/feed/" rel="self" type="application/rss+xml" />
	<link>https://lobsterpot.com.au/blog/2011/04/12/select-and-where-but-no-from-clause/</link>
	<description></description>
	<lastBuildDate>Thu, 16 Jul 2015 03:15:37 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>
		By: Rob Farley		</title>
		<link>https://lobsterpot.com.au/blog/2011/04/12/select-and-where-but-no-from-clause/#comment-1709</link>

		<dc:creator><![CDATA[Rob Farley]]></dc:creator>
		<pubDate>Thu, 16 Jul 2015 03:15:37 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.lobsterpot.com.au/?p=2915#comment-1709</guid>

					<description><![CDATA[Try:
 &#160; &#160;SELECT *
 &#160; &#160;FROM (
 &#160; &#160; &#160; &#160;SELECT ... FROM ....
 &#160; &#160; &#160; &#160;UNION
 &#160; &#160; &#160; &#160;SELECT ... FROM ....
 &#160; &#160;) AS u
 &#160; &#160;WHERE ...]]></description>
			<content:encoded><![CDATA[<p>Try:<br />
 &nbsp; &nbsp;SELECT *<br />
 &nbsp; &nbsp;FROM (<br />
 &nbsp; &nbsp; &nbsp; &nbsp;SELECT &#8230; FROM &#8230;.<br />
 &nbsp; &nbsp; &nbsp; &nbsp;UNION<br />
 &nbsp; &nbsp; &nbsp; &nbsp;SELECT &#8230; FROM &#8230;.<br />
 &nbsp; &nbsp;) AS u<br />
 &nbsp; &nbsp;WHERE &#8230;</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: RK		</title>
		<link>https://lobsterpot.com.au/blog/2011/04/12/select-and-where-but-no-from-clause/#comment-1708</link>

		<dc:creator><![CDATA[RK]]></dc:creator>
		<pubDate>Wed, 15 Jul 2015 22:09:27 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.lobsterpot.com.au/?p=2915#comment-1708</guid>

					<description><![CDATA[I am combining two tables using a UNION operator. However, I would like to choose a subset of the resulting data with a where clause. I am getting an error when I use the where clause. Is there a simple solution to this problem.]]></description>
			<content:encoded><![CDATA[<p>I am combining two tables using a UNION operator. However, I would like to choose a subset of the resulting data with a where clause. I am getting an error when I use the where clause. Is there a simple solution to this problem.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Rob Farley		</title>
		<link>https://lobsterpot.com.au/blog/2011/04/12/select-and-where-but-no-from-clause/#comment-1707</link>

		<dc:creator><![CDATA[Rob Farley]]></dc:creator>
		<pubDate>Mon, 18 Apr 2011 06:33:48 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.lobsterpot.com.au/?p=2915#comment-1707</guid>

					<description><![CDATA[Hi Paul,
I&#039;m not convinced it is nicer.
It&#039;s almost identical (but has an extra operator) to the version that uses VALUES. But when you compare it to the UNION ALL version, you see a few differences.
The difference that I see as significant is that the Filter for OrigShip appears before the concatenation, but when using UNPIVOT, it puts the Filter at the end (with 125860 being checked, 94404 going through), instead of a start-up filter that would be being used only 31465 times.
But my main point is regarding the flexibility. UNPIVOT feels so inflexible, whereas APPLY can be used in far more ways.
Thanks for your comment though - I always appreciate your feedback on these things.
Rob]]></description>
			<content:encoded><![CDATA[<p>Hi Paul,<br />
I&#8217;m not convinced it is nicer.<br />
It&#8217;s almost identical (but has an extra operator) to the version that uses VALUES. But when you compare it to the UNION ALL version, you see a few differences.<br />
The difference that I see as significant is that the Filter for OrigShip appears before the concatenation, but when using UNPIVOT, it puts the Filter at the end (with 125860 being checked, 94404 going through), instead of a start-up filter that would be being used only 31465 times.<br />
But my main point is regarding the flexibility. UNPIVOT feels so inflexible, whereas APPLY can be used in far more ways.<br />
Thanks for your comment though &#8211; I always appreciate your feedback on these things.<br />
Rob</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Paul White		</title>
		<link>https://lobsterpot.com.au/blog/2011/04/12/select-and-where-but-no-from-clause/#comment-1706</link>

		<dc:creator><![CDATA[Paul White]]></dc:creator>
		<pubDate>Mon, 18 Apr 2011 05:04:42 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.lobsterpot.com.au/?p=2915#comment-1706</guid>

					<description><![CDATA[Hey Rob,
I&#039;m a fan of UNPIVOT myself. &#160;The following produces a nicer query plan (to my mind anyway) than the APPLY syntax:
WITH &#160; &#160;Src
AS &#160; &#160; &#160;(
 &#160; &#160; &#160; &#160;SELECT &#160;SalesOrderID, 
 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;OrderDate, 
 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;ShipDate, 
 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;DueDate,
 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;OrigShip = 
 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;CASE 
 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;WHEN ShipDate &#062; DATEADD(DAY, 7, OrderDate) 
 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;THEN DATEADD(DAY, 7, OrderDate) 
 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;END
 &#160; &#160; &#160; &#160;FROM &#160; &#160;Sales.SalesOrderHeader
 &#160; &#160; &#160; &#160;)
SELECT &#160;D.SalesOrderID, 
 &#160; &#160; &#160; &#160;D.DateType, 
 &#160; &#160; &#160; &#160;D.[Date]
FROM &#160; &#160;Src
UNPIVOT (
 &#160; &#160; &#160; &#160;[Date] FOR DateType IN (OrderDate, ShipDate, DueDate, OrigShip)
 &#160; &#160; &#160; &#160;) AS D
;
What do you think?
Paul]]></description>
			<content:encoded><![CDATA[<p>Hey Rob,<br />
I&#8217;m a fan of UNPIVOT myself. &nbsp;The following produces a nicer query plan (to my mind anyway) than the APPLY syntax:<br />
WITH &nbsp; &nbsp;Src<br />
AS &nbsp; &nbsp; &nbsp;(<br />
 &nbsp; &nbsp; &nbsp; &nbsp;SELECT &nbsp;SalesOrderID,<br />
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OrderDate,<br />
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ShipDate,<br />
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DueDate,<br />
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OrigShip =<br />
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CASE<br />
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WHEN ShipDate &gt; DATEADD(DAY, 7, OrderDate)<br />
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;THEN DATEADD(DAY, 7, OrderDate)<br />
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;END<br />
 &nbsp; &nbsp; &nbsp; &nbsp;FROM &nbsp; &nbsp;Sales.SalesOrderHeader<br />
 &nbsp; &nbsp; &nbsp; &nbsp;)<br />
SELECT &nbsp;D.SalesOrderID,<br />
 &nbsp; &nbsp; &nbsp; &nbsp;D.DateType,<br />
 &nbsp; &nbsp; &nbsp; &nbsp;D.[Date]<br />
FROM &nbsp; &nbsp;Src<br />
UNPIVOT (<br />
 &nbsp; &nbsp; &nbsp; &nbsp;[Date] FOR DateType IN (OrderDate, ShipDate, DueDate, OrigShip)<br />
 &nbsp; &nbsp; &nbsp; &nbsp;) AS D<br />
;<br />
What do you think?<br />
Paul</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Rob Farley		</title>
		<link>https://lobsterpot.com.au/blog/2011/04/12/select-and-where-but-no-from-clause/#comment-1705</link>

		<dc:creator><![CDATA[Rob Farley]]></dc:creator>
		<pubDate>Mon, 18 Apr 2011 00:40:00 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.lobsterpot.com.au/?p=2915#comment-1705</guid>

					<description><![CDATA[Hi Joe,
Yes, I&#039;m most definitely restricting myself to T-SQL here. Oracle was my first RDBMS, and I was fine with following its rules regarding SET and DUAL. Having moved to the T-SQL world, I discovered that ANSI was broken in other ways. Some I liked, some I didn&#039;t.
As much as I would like T-SQL to be as ANSI-like as possible, I also try to welcome the differences.
Rob]]></description>
			<content:encoded><![CDATA[<p>Hi Joe,<br />
Yes, I&#8217;m most definitely restricting myself to T-SQL here. Oracle was my first RDBMS, and I was fine with following its rules regarding SET and DUAL. Having moved to the T-SQL world, I discovered that ANSI was broken in other ways. Some I liked, some I didn&#8217;t.<br />
As much as I would like T-SQL to be as ANSI-like as possible, I also try to welcome the differences.<br />
Rob</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Joe Celko		</title>
		<link>https://lobsterpot.com.au/blog/2011/04/12/select-and-where-but-no-from-clause/#comment-1704</link>

		<dc:creator><![CDATA[Joe Celko]]></dc:creator>
		<pubDate>Sun, 17 Apr 2011 18:16:19 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.lobsterpot.com.au/?p=2915#comment-1704</guid>

					<description><![CDATA[T-SQL overloads the SELECT keyuword; ANSI does not. 
The &#060;select sttement&#062; does require a &#060;FROM clause&#062;; read your ANSI/ISO Standards. &#160;I am doing this off the top of my head. 
The &#060;assign statement&#062; in Standard SQL is
 SET &#060;target row consructor&#062; = &#060;expression row constructor&#062;;
The &#060;assign statement&#062; in T-SQL dialect is
 [SET &#124; SELECT] &#060;scalar assignment&#062; {, &#060;scalar assignment&#062;};
 &#160;&#060;scalar assignment&#062; ::= &#060;variable&#062; = &#060;expression&#062;
Whwre SET can take only one scalar assignment. And, as you pointed out, T-SQL is a nightmare of bad proprietary syntax.]]></description>
			<content:encoded><![CDATA[<p>T-SQL overloads the SELECT keyuword; ANSI does not.<br />
The &lt;select sttement&gt; does require a &lt;FROM clause&gt;; read your ANSI/ISO Standards. &nbsp;I am doing this off the top of my head.<br />
The &lt;assign statement&gt; in Standard SQL is<br />
 SET &lt;target row consructor&gt; = &lt;expression row constructor&gt;;<br />
The &lt;assign statement&gt; in T-SQL dialect is<br />
 [SET | SELECT] &lt;scalar assignment&gt; {, &lt;scalar assignment&gt;};<br />
 &nbsp;&lt;scalar assignment&gt; ::= &lt;variable&gt; = &lt;expression&gt;<br />
Whwre SET can take only one scalar assignment. And, as you pointed out, T-SQL is a nightmare of bad proprietary syntax.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Matt Velic		</title>
		<link>https://lobsterpot.com.au/blog/2011/04/12/select-and-where-but-no-from-clause/#comment-1703</link>

		<dc:creator><![CDATA[Matt Velic]]></dc:creator>
		<pubDate>Tue, 12 Apr 2011 17:34:52 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.lobsterpot.com.au/?p=2915#comment-1703</guid>

					<description><![CDATA[Thanks for participating, Rob! I knew that FROM was optional, but I hadn&#039;t thought of using APPLY instead of UNPIVOT. In my defense, I&#039;ve never had to UNPIVOT anything, but I&#039;m happy to have found my new method for when I do!]]></description>
			<content:encoded><![CDATA[<p>Thanks for participating, Rob! I knew that FROM was optional, but I hadn&#8217;t thought of using APPLY instead of UNPIVOT. In my defense, I&#8217;ve never had to UNPIVOT anything, but I&#8217;m happy to have found my new method for when I do!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Brad Schulz		</title>
		<link>https://lobsterpot.com.au/blog/2011/04/12/select-and-where-but-no-from-clause/#comment-1702</link>

		<dc:creator><![CDATA[Brad Schulz]]></dc:creator>
		<pubDate>Tue, 12 Apr 2011 06:31:48 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.lobsterpot.com.au/?p=2915#comment-1702</guid>

					<description><![CDATA[Excellent argument for the UNION ALL approach! &#160;I like it!
(And thanks for the mention).
--Brad]]></description>
			<content:encoded><![CDATA[<p>Excellent argument for the UNION ALL approach! &nbsp;I like it!<br />
(And thanks for the mention).<br />
&#8211;Brad</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
