[thelist] Re-Using A Sub Query Value

Tab Alleman talleman at Lumpsum.com
Thu Jun 22 13:36:31 CDT 2006


I'm pretty sure it isn't... but you could make your whole query into a derived table to do something similar, like this:

SELECT
	someColumns
,	item4+myTotal AS grandtotal
FROM (
	SELECT
		someColumns
	,	(SELECT blahblah) AS myTotal
	,	item4
	FROM blahblah WHERE blahblah
) mainquery




> -----Original Message-----
> From: thelist-bounces at lists.evolt.org
> [mailto:thelist-bounces at lists.evolt.org]On Behalf Of Peter Brunone
> (EasyListBox.com)
> Sent: Thursday, June 22, 2006 2:06 PM
> To: thelist at lists.evolt.org; thelist at lists.evolt.org
> Subject: Re: [thelist] Re-Using A Sub Query Value
> 
> 
> 
> 		I still don't understand why you're using a 
> subquery here.  Wouldn't the following make more sense?
> 
> SELECT a.id1, a.item 2, b.item3, a.item4+b.item3 AS GrandTotal 
> FROM table1 a, table2 b, blah blah
> WHERE b.id = a.id and blah blah 
> 
> Peter
> 
> 				From: "Casey Crookston" 
> caseyc at IntelliSoftmn.com
> 
> Okay, this is a continuation of my previous post. Once you have
> selected a value in a sub query, is it possible to reference 
> that value
> without performing the sub query again?
> 
> Example:
> 
> SELECT a.id1, a.item 2, (select b.item3 FROM blah WHERE b.id 
> = a.id) AS
> myTotal, a.item4+myTotal AS GrandTotal FROM blah blah WHERE blah blah
> 
> Does that make sense?
> 
> Thanks,
> 
> Casey
> -- 
> 
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
> 
> For unsubscribe and other options, including the Tip Harvester 
> and archives of thelist go to: http://lists.evolt.org 
> Workers of the Web, evolt ! 
> 



More information about the thelist mailing list