sql - MySQL select and update multiple rows from same table -
generally want select rows orders table in database, created after date, , update office_id field of selected rows specific value 12. mysql version 5.5.43. @ firs trying put in 1 sql statement so:
update `order` set office_id = 12 id in ( select id `order` created_at >= date_format( '2014-07-02 00:00:00', '%y.%m.%d 00:00:00' ) ); and getting error: #1093 - can't specify target table 'order' update in clause.
next tried select .. update statment so:
start transaction; select id `order` created_at >= date_format( '2014-07-02 00:00:00', '%y.%m.%d 00:00:00' ) update; update `order` set office_id = 12 id in ( id ); commit; which worked, if select .. update statement returns no rows, office_id = 12 applied rows in orders table, defenetely don't want.
i'm looking in modification 1st or 2nd solution propper working.
it's simpler you're making it. can apply clause directly update statement.
update `order` set office_id = 12 created_at >= date_format( '2014-07-02 00:00:00', '%y.%m.%d 00:00:00' );
Comments
Post a Comment