| | |
Update Stmt - Update same record multiple times
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2009
Posts: 7
Reputation:
Solved Threads: 0
Hi,
I've having a bit of difficulty with an update statement.
The following select statement returns 34 records...
If I add a distinct clause to the statement, only 9 records are returned from the budget table.
I'm attempting to update the budget table 34 times, which means updating the same record from the budget table multiple times in the same update statement.
I've tried variations of the update statement, but only 9 records are ever updated.
Can anyone give any advice on how to go about updating the 34 records in one update statement.
Many Thanks!
I've having a bit of difficulty with an update statement.
The following select statement returns 34 records...
MySQL Syntax (Toggle Plain Text)
SELECT b.* FROM budget as b INNER JOIN ntime t on b.feeearnerkey=t.feeearnerkey INNER JOIN DATE d on t.datekey=d.datekey INNER JOIN acts a on t.activitykey=a.activitykey WHERE a.activitycode IN (11,12,13,14,15,16,17,18) AND b.fiscalmonth=d.fiscalmonthnum AND b.fiscalyear=d.fiscalyearnum AND b.budgetkey=1 AND t.feeearnerkey=520
If I add a distinct clause to the statement, only 9 records are returned from the budget table.
I'm attempting to update the budget table 34 times, which means updating the same record from the budget table multiple times in the same update statement.
I've tried variations of the update statement, but only 9 records are ever updated.
MySQL Syntax (Toggle Plain Text)
UPDATE budget as b INNER JOIN ntime t on b.feeearnerkey=t.feeearnerkey INNER JOIN DATE d on t.datekey=d.datekey INNER JOIN acts a on t.activitykey=a.activitykey SET b.budgetamount=b.budgetamount - (t.minutes / 60) WHERE a.activitycode IN (11,12,13,14,15,16,17,18) AND b.fiscalmonth=d.fiscalmonthnum AND b.fiscalyear=d.fiscalyearnum AND b.budgetkey=1 AND t.feeearnerkey=520 UPDATE TIME t INNER JOIN budget b on t.feeearnerkey=b.feeearnerkey INNER JOIN DATE d on t.datekey=d.datekey INNER JOIN acts a on t.activitykey=a.activitykey SET b.budgetamount=b.budgetamount - (t.minutes / 60) WHERE a.activitycode IN (11,12,13,14,15,16,17,18) AND b.fiscalmonth=d.fiscalmonthnum AND b.fiscalyear=d.fiscalyearnum AND b.budgetkey=1 AND t.feeearnerkey=520
Can anyone give any advice on how to go about updating the 34 records in one update statement.
Many Thanks!
•
•
Join Date: Aug 2008
Posts: 1,160
Reputation:
Solved Threads: 137
•
•
•
•
If I add a distinct clause to the statement, only 9 records are returned from the budget table.
if the update isn't working properly, can you give us a little more of the schema and also what the distinct column is?
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
•
•
Join Date: Jun 2009
Posts: 7
Reputation:
Solved Threads: 0
yes, I definately need to update the budget table 34 times.
The 'budgetamount' field stores an hourly target value for a particular month & year. I need to deduct any minutes (t.minutes / 60) that exist in the 'time' table for the particular month and year.
So although in the budget table, there can only be one entry for a particular month and year, many entries can exist in the time table for that particular month and year.
Maybe I need to apply some kind of aggregation to the time table before deducting from the budgetamount value?
The 'budgetamount' field stores an hourly target value for a particular month & year. I need to deduct any minutes (t.minutes / 60) that exist in the 'time' table for the particular month and year.
So although in the budget table, there can only be one entry for a particular month and year, many entries can exist in the time table for that particular month and year.
Maybe I need to apply some kind of aggregation to the time table before deducting from the budgetamount value?
Last edited by nickj; Jun 16th, 2009 at 3:56 am.
•
•
Join Date: Aug 2008
Posts: 1,160
Reputation:
Solved Threads: 137
ahhh, so for every record that exists in acts you are needing an update
my advice would be to use a sql 'for each' loop, you can use a cursor and iterate through each row and execute the update statement in there
my advice would be to use a sql 'for each' loop, you can use a cursor and iterate through each row and execute the update statement in there
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
![]() |
Similar Threads
- How to Update a record in a database (PHP)
- update record error-mysql_numrows(): supplied argument is not a valid MySQL (PHP)
- update a record on load (Oracle)
- vb6 update record in the database (Visual Basic 4 / 5 / 6)
- Update record Problem. (ASP.NET)
- Problem with Update Record in MS ACCESS (VB.NET)
- Searching for a record in multiple tables (VB.NET)
- [Please HELP] Cannot Update Record (PHP)
Other Threads in the MySQL Forum
- Previous Thread: Can Crystal Reports be used with MySQL?
- Next Thread: Supplied argument is not a valid MySQL result resource
| Thread Tools | Search this Thread |
agplv3 alfresco api artisticlicense aws bizspark breathalyzer camparingtocolumns changingprices cmg communityjournalism contentmanagement contractors copyright count court crm database design developer development distinct drupal dui ec2 email enterprise eudora facebook form foss gnu government gpl greenit groklaw groupware hiring hyperic images innerjoins insert ip joebrockmeier join journalism keyword keywords kickfire laptop law legal license licensing linux maintenance managing mariadb matchingcolumns metron micromanage microsoft microsoftexchange mindtouch montywidenius mozilla multiple music mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opendatabasealliance opengovernment opensource oracle penelope php query referencedesign reorderingcolumns resultset saas select sharepoint simpledb sourcecode spotify sql sugarcrm syntax techsupport thunderbird transparency virtualization






