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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:05:50+00:00 2026-06-06T18:05:50+00:00

I have tried the following MySQL update but it only sets the first field

  • 0

I have tried the following MySQL update but it only sets the first field c.avg_price_dil and not the second field c.avg_dilution.

The strange part is that when I split the update into two parts as shown below, both work with both fields being updated. Is there something about group based functions that is affecting this call?

Two fields updated – only c.avg_price_dil is updated.

update corp_act as c
inner join (
  select 
      m.gvkey, m.gvkey_iid, m.date_base, avg(m.price_dil) as avg_price, 
      avg(m.dilution) as avg_dilution
  from master as m
  inner join corp_act as c
  on c.gvkey = m.gvkey AND
      m.date_base between c.date_base AND 
                          LAST_DAY(c.date_base + INTERVAL 11 MONTH)
  where c.actioncd not in ('N/C','REA','SPN') AND 
        c.actioncd IS NOT NULL
  group by m.gvkey_iid, c.actioncd) as x
on 
   x.gvkey = c.gvkey AND 
   x.date_base = c.date_base
set 
    c.avg_price_dil = if(x.avg_price is null, 0, x.avg_price) AND
    c.avg_dilution = if(x.avg_dilution is null, 0, x.avg_dilution)

When separated into two updates, both work:

Dilution update: – works fine

update corp_act as c
inner join (
  select 
       m.gvkey, m.gvkey_iid, m.date_base, avg(m.dilution) as avg_dilution
  from master as m
  inner join corp_act as c
  on c.gvkey = m.gvkey AND
     m.date_base between c.date_base AND 
                         LAST_DAY(c.date_base + INTERVAL 11 MONTH)
  where c.actioncd not in ('N/C','REA','SPN') AND 
        c.actioncd IS NOT NULL
  group by m.gvkey_iid, c.actioncd) as x
on 
   x.gvkey = c.gvkey AND 
   x.date_base = c.date_base
set 
   c.avg_dilution = if(x.avg_dilution is null, 0, x.avg_dilution)

Price Update: – works fine

update corp_act as c
inner join (
  select 
     m.gvkey, m.gvkey_iid, m.date_base, avg(m.price_dil) as avg_price
  from master as m
  inner join corp_act as c
  on c.gvkey = m.gvkey AND
     m.date_base between c.date_base AND 
                         LAST_DAY(c.date_base + INTERVAL 11 MONTH)
  where c.actioncd not in ('N/C','REA','SPN') AND 
        c.actioncd IS NOT NULL
  group by m.gvkey_iid, c.actioncd) as x
on 
   x.gvkey = c.gvkey AND 
   x.date_base = c.date_base
set 
   c.avg_price_dil = if(x.avg_price is null, 0, x.avg_price)

The only difference between these two is that I only use the avg function once in the individual ones.

Any ideas?
Thanks for your help.

  • 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-06T18:05:52+00:00Added an answer on June 6, 2026 at 6:05 pm

    set
    c.avg_price_dil = if(x.avg_price is null, 0, x.avg_price) AND
    c.avg_dilution = if(x.avg_dilution is null, 0, x.avg_dilution)

    Try replacing AND with a comma (,).

    http://dev.mysql.com/doc/refman/5.0/en/update.html

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

Sidebar

Related Questions

I have tried the following: <%= image_tag '...path_to_img', :filter => alpha(opacity=50) %> But it
I have tried the following code but has no effect: Imports system.Runtime.InteropServices <DllImport(UxTheme.DLL, BestFitMapping:=False,
I have tried the following but it seems the folder gets created on the
I have no idea why this wont work but I have tried the following:
I have tried for hours now to update a MySQL table with PHP. I
I have tried all combinations of single quotes, double quotes etc but the following
I have tried following queries to get my facebook fan page insights data SELECT
I have tried the following <input type=file name=upload multiple=multiple value=MyText> However the text on
I have tried the following program for writing the contents into Spreadsheet. I downloaded
I have tried the following code: $('a.buildMenu').click(function (event) { // Prevent normal behaviour event.preventDefault();

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.