Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MySQL Table update returning error

Posted on 2013-06-05
7
Medium Priority
?
560 Views
Last Modified: 2013-08-20
Hi,

I am using following SQL

update email a, contact b
set a.email =  CONCAT('abcd+' ,b.first_name,', ',b.last_name, '@gmail.com')  
where a.contact_id=b.id

I have an error
 #1442 - Can't update table 'contact' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.

There are no triggers on the table.

Thanks
0
Comment
Question by:crazywolf2010
7 Comments
 
LVL 4

Expert Comment

by:apreed
ID: 39222652
Is this a stored function? If so, check the SQL code that calls this function and make sure "contact" is not already used as an alias in there within the same session.
0
 

Author Comment

by:crazywolf2010
ID: 39222676
Hi,
This is not stored function at all. I am running it under phpmyadmin.

Thanks
0
 
LVL 5

Accepted Solution

by:
sriramiyer earned 668 total points
ID: 39222796
you can try this,

update email a, contact b
set a.email =  CONCAT('abcd' ,b.first_name,b.last_name, '@gmail.com')  
where a.contact_id=b.id
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Assisted Solution

by:nemws1
nemws1 earned 1332 total points
ID: 39223944
Try using the newer style syntax for such things (instead of doing a cross join)

UPDATE email AS a
  JOIN contact AS b
    ON a.contact_id = b.id
SET a.email = CONCAT('abcd', b.first_name, b.last_name, '@gmail.com')
;

Open in new window

0
 

Author Comment

by:crazywolf2010
ID: 39224037
Exact same error
0
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
ID: 39224378
What is the scenario I don't understand your question are you updating using two tables ?? can you post image for your table??
0
 
LVL 23

Assisted Solution

by:nemws1
nemws1 earned 1332 total points
ID: 39226126
Is there a trigger on the 'contact' table?  I'm assuming when you originally stated "There are no triggers on the table." you meant the 'email' table.

Can you run this SQL command just to double-check? (replace 'your_database_name' with the name of your database)

SELECT TRIGGER_NAME
    , EVENT_OBJECT_TABLE
FROM information_schema.TRIGGERS
WHERE TRIGGER_SCHEMA = 'your_database_name'
;

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

877 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