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

  • Home
  • SEARCH
  • 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 7619811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:47:00+00:00 2026-05-31T03:47:00+00:00

I am trying to update certain pieces of data based on a select statement

  • 0

I am trying to update certain pieces of data based on a select statement within a trigger. The select statement is as follows:

SELECT col1 
FROM tbl1 d 
  LEFT OUTER JOIN tbl2 e ON D.colid = E.colid

I then want to change the data returned from this statement to a new value calculated in the trigger. I thought it might be something like this e.col1 = COUNTER but that doesn’t seem to work. Any help with updating this data would be great, thanks.

EDIT: I’ve changed the select query to retrieve the data I actually want. The one I stated above was wrong.

UPDATE tbl2 SET col1 = COUNTER
WHERE EXISTS(SELECT col1
FROM tbl1 d 
    LEFT OUTER JOIN tbl2 e ON D.colid = E.colid 
    WHERE col2= :new.col2);

I should state again that the problem is when using the code above is that the whole column in the table is updated as opposed to the data returned by the select query.

EDIT:
tbl1 contains columns colid, col2 and

tbl2 contains columns colid, col1

Trigger is before insert on tbl1.

  • 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-05-31T03:47:02+00:00Added an answer on May 31, 2026 at 3:47 am

    It would help if you’d told us which table the trigger was on, what kind of trigger, and what columns are in what table. I still can’t quite figure out what you’re trying to do with these updates.

    UPDATE tbl2 SET col1 = COUNTER
    WHERE EXISTS(SELECT col1
    FROM tbl1 d 
        LEFT OUTER JOIN tbl2 e ON D.colid = E.colid 
        WHERE col2= :new.col2);
    

    I think the problem is that you are doing a LEFT JOIN in your inner select statement. Since there will always be a row in the inner query and you’re doing this in an EXISTS clause, it will always match a row, and your UPDATE will fire on every row in the table.

    Maybe this will work better for you:

    UPDATE tbl2 SET col1 = COUNTER
    WHERE EXISTS(SELECT col1
    FROM tbl1 d 
        INNER JOIN tbl2 e ON D.colid = E.colid 
        WHERE col2= :new.col2);
    

    I will say that if this trigger is on tbl2, then this is a bad way of doing this, because you’re likely to run into the mutating table problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to update a field in a table with data from another
I am trying to select rows which are within a certain time period: $sql
Hi I am trying to update a div with some html from another div.
Problem: I am trying to update a List. If a certain item's ID already
I'm trying to update a legacy app that does all its data storage in
I am trying to access and update certain attributes of an element in a
I am trying to update as well as save data to my database using
I'm trying to make an array, and then update the values of certain cells
I'm trying to update certain controls according to a selection in a dropdown list.
I am trying to get a parameter for my update from the gridview but

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.