Solved

MySQL Table update returning error

Posted on 2013-06-05
7
542 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 167 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 23

Assisted Solution

by:nemws1
nemws1 earned 333 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 333 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

752 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