 




<?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: Reference a query object from another query</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/reference-a-query-object-from-another-query/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/reference-a-query-object-from-another-query/</link>
	<description></description>
	<lastBuildDate>Sat, 25 May 2013 00:24:16 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: steveg44</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/reference-a-query-object-from-another-query/#comment-39146</link>
		<dc:creator>steveg44</dc:creator>
		<pubDate>Thu, 03 Nov 2005 13:17:28 +0000</pubDate>
		<guid isPermaLink="false">#comment-39146</guid>
		<description><![CDATA[mdaponte reported the SQL Server 2000 inner query technique.  This also works with DB2 UDB.

Further, UDB provides the following construct, a common-table-expression, that makes for an even simpler to understand query...

WITH query_data (field1, field2) AS
   (SELECT xxx, yyy FROM some_table WHERE ...)
SELECT t1.field1,
       q1.field2
  FROM table_data t1, query_data q1
 WHERE t1.field1 = q1.field1

This example also uses correlated coefficients for ease of coding JOIN conditions.  Note that it isn&#039;t necessary to retrieve q1.field1 since it will always have the same value as t1.field1.

Note that the complete query_data result set is not available outside the full select statement so this technique is valid only if you only want the end result.]]></description>
		<content:encoded><![CDATA[<p>mdaponte reported the SQL Server 2000 inner query technique.  This also works with DB2 UDB.</p>
<p>Further, UDB provides the following construct, a common-table-expression, that makes for an even simpler to understand query&#8230;</p>
<p>WITH query_data (field1, field2) AS<br />
   (SELECT xxx, yyy FROM some_table WHERE &#8230;)<br />
SELECT t1.field1,<br />
       q1.field2<br />
  FROM table_data t1, query_data q1<br />
 WHERE t1.field1 = q1.field1</p>
<p>This example also uses correlated coefficients for ease of coding JOIN conditions.  Note that it isn&#8217;t necessary to retrieve q1.field1 since it will always have the same value as t1.field1.</p>
<p>Note that the complete query_data result set is not available outside the full select statement so this technique is valid only if you only want the end result.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mdaponte</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/reference-a-query-object-from-another-query/#comment-39147</link>
		<dc:creator>mdaponte</dc:creator>
		<pubDate>Thu, 27 Oct 2005 10:09:28 +0000</pubDate>
		<guid isPermaLink="false">#comment-39147</guid>
		<description><![CDATA[You could create a view with the query, and then you could use it in any query:

create view xxx as 
   select ...

And I guess that you could also use it as a inner query (at least in SQL Server 2000 you could), for example:

select *
  from table1, (select t2.x, y, z
                  from table2 t2, table3 t3
                 where t2.x = t3.x) as new_table
 where table1.x = new_table.x



]]></description>
		<content:encoded><![CDATA[<p>You could create a view with the query, and then you could use it in any query:</p>
<p>create view xxx as<br />
   select &#8230;</p>
<p>And I guess that you could also use it as a inner query (at least in SQL Server 2000 you could), for example:</p>
<p>select *<br />
  from table1, (select t2.x, y, z<br />
                  from table2 t2, table3 t3<br />
                 where t2.x = t3.x) as new_table<br />
 where table1.x = new_table.x</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 3/10 queries in 0.033 seconds using memcached
Object Caching 281/287 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-05-25 00:28:41 -->