473,395 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

MYSQL trigger You can't specify target table 'XXX' for update in FROM clause

I am trying to convert mssql triggers to mysql. I am very new to Mysql and would like some help with my code. My queries work but there has to be a more efficient way to write them. I would greatly appreciate any help. the following is a trigger that works until I add the last update statement. thanks for the help.
Mysql 5

Expand|Select|Wrap|Line Numbers
  1. delimiter //
  2. Create TRIGGER User_Rating_Avg After Insert on bksite.Ratings
  3. FOR EACH ROW
  4. BEGIN
  5. UPDATE bksite.bookkeepers SET User_Cost_Avg=
  6. (SELECT SUM(cost)/(SELECT count(*) FROM bksite.ratings where bkid = new.bkid) from ratings where bkid = new.bkid)
  7. where bkid = new.bkid;
  8.  
  9. UPDATE bksite.bookkeepers SET User_Knowledge_Avg=
  10. (SELECT SUM(knowledge)/(SELECT count(*) FROM bksite.ratings where bkid = new.bkid) from ratings where bkid = new.bkid)
  11. where bkid = new.bkid;
  12.  
  13. UPDATE bksite.bookkeepers SET User_Speed_Avg=
  14. (SELECT SUM(speed)/(SELECT count(*) FROM bksite.ratings where bkid = new.bkid) from ratings where bkid = new.bkid)
  15. where bkid = new.bkid;
  16.  
  17. UPDATE bksite.bookkeepers SET User_Accuracy_Avg=
  18. (SELECT SUM(accuracy)/(SELECT count(*) FROM bksite.ratings where bkid = new.bkid) from ratings where bkid = new.bkid)
  19. where bkid = new.bkid;
  20. END;
  21. //
  22.  
the trigger fails when i insert this last bit. the error is You can't specify target table 'XXX' for update in FROM clause

Expand|Select|Wrap|Line Numbers
  1. UPDATE bksite.bookkeepers SET User_Avg_Total=
  2. (SELECT (User_knowledge_avg + User_Cost_Avg + User_Speed_Avg + User_Accuracy_Avg)/4 FROM Bookkeepers
  3. where bkid =new.bkid);
  4.  
Nov 3 '08 #1
0 4401

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: red85 | last post by:
hello i have mysql 4.1 with win2000 SP3, i know that it is only an alpha and i don't know if someone else has already posted this problem: when i execute this sql UPDATE tableX SET...
8
by: Jason | last post by:
I have a table that matches up Securities and Exchanges. Individual securities can belong on multiple exchanges. One of the columns, named PrimaryExchangeFlag, indicates if a particular exchange is...
2
by: Dima Gofman | last post by:
I have a trigger on UPDATE on a table. I'm running some maintenance UPDATE and DELETE queries which I want the trigger to ignore but at the same time I want other UPDATE queries that other users...
7
by: Jon Maz | last post by:
Hi, I have a MySql problem I hope someone can help me with. I'm trying to run an update on a linking table, the update is running into a Primary Key constraint violation, and in my workaround...
1
by: wesley | last post by:
Hi All, i need to know how to solve the error in the following query: UPDATE table1 SET StopTime = NOW() WHERE StationId = (SELECT StationId FROM table1 WHERE StopTime = "0000-00-00 00:00:00" AND...
2
by: Ted | last post by:
1) In several tables, in my MySQL version, I created columns using something like the following: `ab_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, This...
1
by: santoshborfalkar | last post by:
This is the Trigger which is not working properly during Update, no any record is going to be updated so pls help. I am updating the requisition table when any update in quantity in podetails...
1
by: Jason Hallums | last post by:
New to Mysql; I have created a stored procedure. Using a cursor I traverse the first table. For each row in the cursor I need to determine the correct row in another table to update. Using a...
6
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.