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 8759559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:50:01+00:00 2026-06-13T14:50:01+00:00

I am reluctant to enter this code I came up with below: UPDATE a_fees

  • 0

I am reluctant to enter this code I came up with below:

UPDATE a_fees
SET active = 'N'
WHERE EXISTS
(
SELECT fee_id, (
audit_fees + audit_related_fees + tax_fees + other_fees
) AS total_fees
FROM a_fees
WHERE verified = 'N'
GROUP BY fee_id
HAVING total_fees < 5000);

Because I run this similar code (below) and I get all the results in the table returned, which makes me think this code above will update all the records in the table.
When I do the sub-select, it returns only the portion I am concerned with.
However, when I add the outermost selection statement, it returns the whole table.

SELECT fee_id
FROM a_fees
WHERE EXISTS (

SELECT fee_id, (
audit_fees + audit_related_fees + tax_fees + other_fees
) AS total_fees
FROM a_fees
WHERE verified =  'N'
GROUP BY fee_id
HAVING total_fees <5000;

Any advice how to set active=’N’ for records in the table where the sum of four columns is less than $5,000 would be great. Thanks in advance.

  • 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-13T14:50:03+00:00Added an answer on June 13, 2026 at 2:50 pm

    The EXISTS condition is considered to be met if the subquery returns at least one row.
    So you’re right, the first UPDATE could update all the record of the table.

    You should use IN clause instead of EXISTS, and there’s also no need to use a GROUP BY clause since fee_id is unique:

    SELECT fee_id
    FROM a_fees
    WHERE a_fees.fee_id IN (
      SELECT fee_id
      WHERE
        verified='N' AND
        audit_fees + audit_related_fees + tax_fees + other_fees <5000);
    

    or you should put the condition in the subquery:

    SELECT fee_id
    FROM a_fees
    WHERE EXISTS (
      SELECT fee_id
      FROM a_fees a_fees_1
      WHERE
        verified =  'N'
        AND a_fees_1.fee_id = a_fees.fee_id
        AND audit_fees + audit_related_fees + tax_fees + other_fees <5000);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Answering to this question I stuck with this situation. Using reluctant match in my
All, After my previous experiences I am a little reluctant to ask this -
I'm reluctant to ask this but I can't figure it out. When I run
Part-time reluctant DBA here. I want to change an existing primary key index from
I know that the ? is a greedy quantifier and ?? is the reluctant
I have the array shown below. I would like to have a resultant array
What's the canonical way to manage cryptographic keys associated with particular source code? (e.g.
I'm trying to write a trigger within SQL, and the code within needs to
I am learning stacks right now, I my code compiles find. When I run
I have been reluctant to spend much time learning Silverlight due to what I

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.