Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old November 22nd, 2004, 08:27 PM
Registered User
Join Date: Nov 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Correlated Subquery part of Select List

I see alot of examples of a correlated subquery on the right of a "WHERE" clause, but what about when it is part of the select list, as follows:
select distinct t.personnum,
                round(t.wfctimeinseconds/3600,2) as amount,
                substr(c.customdata,1,1) as shift,
               (select count(*) from vp_alltotals
                    where personnum = t.personnum
                    and applydate = t.applydate
                    and wfctimeinseconds = t.wfctimeinseconds
                    and paycodename = 'Shift Differential') as NumShiftDiff
from vp_alltotals t,
vp_personcustdata c
c.personnum = t.personnum;

This query is really bogging down badly when this select list includes what looks to me like a correlated subquery. Are there better ways to code this ? Use temp tables ?

Old November 24th, 2004, 07:25 AM
Authorized User
Join Date: Oct 2004
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts

I don't know of any problems with using a subquery as part of the select. What is the actual problem you are having?

Similar Threads
Thread Thread Starter Forum Replies Last Post
SELECT list re-ordered stuart.pinfold Classic ASP Basics 0 January 24th, 2007 02:36 PM
Difference between Correlated Subquery and Subquer ramk_1978 SQL Language 2 June 12th, 2006 05:35 AM
Delimited to select list? nameless XSLT 1 January 19th, 2006 08:04 PM
Correlated Subquery Rewrite Needed gstanden SQL Language 5 November 24th, 2004 02:39 PM
SQL Select problem (subquery needed??) deian SQL Language 7 February 3rd, 2004 02:40 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.