Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8416217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:41:04+00:00 2026-06-10T01:41:04+00:00

Is the following problematic? DELETE a FROM WHAnalysis.dbo.tb_r12027dxi_CalculatedData a WHERE EXISTS ( SELECT *

  • 0

Is the following problematic?

DELETE a
FROM WHAnalysis.dbo.tb_r12027dxi_CalculatedData a
WHERE EXISTS
        (
        SELECT * 
        FROM WHAnalysis.dbo.tb_r12027dxi_CalculatedData b
        WHERE 
            b.[Past28Days] = 1 AND
            a.[Index] = b.[Index]
        HAVING SUM(b.Amount) = 0
        )

Reason I’m slightly uneasy about using the above script is that if I run the following it errors:

SELECT * 
FROM WHAnalysis.dbo.tb_r12027dxi_CalculatedData b
WHERE 
    b.[Past28Days] = 1
HAVING SUM(b.Amount) = 0

I understand why this script errors => the select is not grouped on anything therefore the processor does not like the aggregation in the HAVING clause.

But as a sub-query this error does not occur – why? Is this a problematic approach?

EDIT

Ended up using the following:

DELETE a
FROM WHAnalysis.dbo.tb_r12027dxi_CalculatedData a
WHERE a.[Index] IN
    (
    SELECT [Index] 
    FROM WHAnalysis.dbo.tb_r12027dxi_CalculatedData
    WHERE [Past28Days] = 1
    GROUP BY [Index] 
    HAVING SUM(Amount) = 0
    )

But as suggested in answer the following is more readable by simply adding the GROUP BY into the sub-query:

DELETE a
FROM WHAnalysis.dbo.tb_r12027dxi_CalculatedData a
WHERE EXISTS
    (
    SELECT * 
    FROM WHAnalysis.dbo.tb_r12027dxi_CalculatedData b
    WHERE 
            b.[Past28Days] = 1 AND
            a.[Index] = b.[Index]
    GROUP BY b.[Index]
    HAVING SUM(b.Amount) = 0
    )
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T01:41:06+00:00Added an answer on June 10, 2026 at 1:41 am

    It is legal to omit group by and still perform aggregations, therefore having is still a way of limiting results:

    select sum(x)
    from
    (
      select 1 x union all select 2
    ) a
    having sum(x) = 3
    

    Exists() work because everything in select list is ignored. Exists() looks for rows only, and terminates as soon as one is found. You might add group by b.Index to make intent clear to anyone reviewing the code later, or rewrite it using inner join and derived table.

    DELETE a
    FROM WHAnalysis.dbo.tb_r12027dxi_CalculatedData a
    INNER JOIN
            (
            SELECT b.[Index]
            FROM WHAnalysis.dbo.tb_r12027dxi_CalculatedData b
            WHERE 
                b.[Past28Days] = 1
            GROUP BY b.[Index]
            HAVING SUM(b.Amount) = 0
            ) b1
       ON a.[Index] = b1.[Index]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following on from my previous question: Simple inner join in linq How would I
Wikipedia says on A* complexity the following ( link here ): More problematic than
Does anyone know if the following code could be problematic: NSString *addchar = nil;
I'm having a very problematic error with phpthumb: http://phpthumb.gxdlabs.com/ So basically, I have a
I have the following basic code to read a text file from a StreamReader:
I have the following query: ;WITH valRules AS ( SELECT vr.valRuleID, Count(*) AS totalRows,
I have a following workflow in my application: there can be X requests from
I have been having some trouble getting the following to work: <IfModule mod_rewrite.c> DirectoryIndex
the following code is being problematic. <script type=text/javascript src=<javascript/prototype.js></script> <script type=text/javascript> // <![CDATA[ $(document).ready(function
My app contains several singletons (following from this tutorial ). I've noticed however, when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.