MySQL Lists are EOL. Please join:

List:General Discussion« Previous MessageNext Message »
From:Andy Wallace Date:September 16 2010 4:46pm
Subject:Update query problem
View as plain text  
So I'm having a problem with an update query. I have three tables:

Table: A
Columns:   acnt, name, company, email, domain

Table: AM
Columns:   acnt, m_id

Table: M
Columns:   m_id, name, company, email, domain

and I want to conditionally update the columns in one to values from the
other. i.e., I want to put the value of into, but only
if is currently NULL, AND has a usable value (not an empty

This is what I came up with, but it doesn't work - it only replaces the
values where the column in M is not null.

update  A
join   AM on A.acnt = AM.acnt
join    M on AM.m_id = M.m_id
SET    = IF( (!    AND != ''),,, = IF( (! AND != ''),,,   = IF( (!   AND != ''),,,
     M.domain  = IF( (!M.domain  AND A.domain != ''),  A.domain,  M.domain)

Any thoughts?


Andy Wallace
iHOUSEweb, Inc.
(866) 645-7700 ext 219
There are two ways to build software:
Make it so simple that there are obviously no bugs,
or make it so complex that there are no obvious bugs.
skip lockingmonloi perez12 Sep
  • Re: skip lockingMichael Satterwhite12 Sep
    • Re: skip lockingmonloi perez16 Sep
      • Re: skip lockingNilton Moura16 Sep
        • Update query problemAndy Wallace16 Sep
          • RE: Update query problemTravis Ard16 Sep
Re: skip lockingNilton Moura18 Sep