Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MySQL Table update returning error

Posted on 2013-06-05
7
Medium Priority
?
555 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
[X]
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
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
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
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…
Suggested Courses

688 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