informix query to update a temp table

Posted on 2010-09-07
Last Modified: 2013-12-24
trying to up update a temp table using Aqua Data studio conencting to an informix DB

audit1 temp table
mks_prospectid is blank want to update it
ID        mks_prospectid

client1 temp table
ID        newclientid
1         101
2          111
3           52523

after the below sql is run we want the audit1 temp table to show the same results as newclientid when the both tables are matched by ID - but we get a syntax error?

-- audit1 – temp table
-- client1 – temp table

update audit1
set mks_prospectid = (select newclientid from client1)
inner join client1 on mks_prospectid = clientid

Question by:JCTDD
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3

Expert Comment

ID: 33624038
The correct query is:

update audit1
set mks_prospectid = (select newclientid
                                       from client1
                                    where audit1.mks_prospectid = client1.clientid)

Expert Comment

ID: 33624043
OR if you do like to use join:

update audit1
set mks_prospectid = client1.newclientid
from audit1 inner join client1
        on audit1.mks_prospectid = client1.clientid

Expert Comment

ID: 33624054
It seems that in both queries,

"audit1.mks_prospectid = client1.clientid"

should be modified to:

"audit1.auditid = client1.clientid"


"audit1.ID = client1.ID"

depending on the actual name of the ID column.

Author Comment

ID: 33624175
for this query:
update audit1
set mks_prospectid = (select newclientid
                                       from client1
                                    where audit1.mks_prospectid = client1.clientid)

get err
>[Error] Script lines: 1-3 --------------------------

 [Informix][Informix ODBC Driver][Informix]Cannot modify table or view used in subquery.

another query we use get the same err

update mktngsurvey_bcs
set mks_newclientid = (select newclientid from pro_bcs
                        inner join mktngsurvey_bcs on prospect_id = mks_prospectid
                        and newclientid is not null and newclientid <> '')
where exists  ( select mks_prospectid from mktngsurvey_bcs
inner join pro_bcs on mks_prospectid = prospect_id)

>[Error] Script lines: 1-7 --------------------------

 [Informix][Informix ODBC Driver][Informix]Cannot modify table or view used in subquery.
update mktngsurvey_bcs

Accepted Solution

flutophilus earned 500 total points
ID: 33628845
Attached code snippet does what you say you want to achieve.

create temp table audit1 (
id integer,
mks_prospectid integer);

insert into audit1 (id) values(1);
insert into audit1 (id) values(2);
insert into audit1 (id) values(3);

create table client1 (
id integer,
clientid integer);

insert into client1 values(1,101);
insert into client1 values(2, 111);
insert into client1 values(3, 52523);

update audit1
set mks_prospectid =
(select client1.clientid 
from client1
where =
where 1=1;

select * from audit1;

id  mks_prospectid
1   101
2   111
3   525253

Open in new window


Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question