mysql - Syntax of a multi-row update that updates specific rows with unique information -
i've been having hard time finding example of trying do.
i have multidimensional array containing 1-n entries. want update table in mysql array, want update rows in single query. wasn't able find examples of multi-row update set values multiple columns , had clause functionality determine rows updated.
the table working setup this:
table name varchar, quota int, warehouse int, production int, missing int the array ordered this, table.name corresponds material name:
$list = array( 'material name one'=>array(1000,200,600,200), 'material name two'=>array(5000,0,4500,500) ); could please provide example of how form type of syntax?
i want use single update size of array/table may grow quite large , i'm under impression method better making hundreds of small updates in quick succession.
first of don't see wrong separately executed updates prepared statements.
but if want reason implement multi row update need build query this
update table1 t join ( select 'material name one' name, 1000 quota, 200 warehouse, 600 production, 200 missing union select 'material name two', 5000, 0, 4500, 500 -- can add rows here -- union ) u on t.name = u.name set t.quota = u.quota, t.warehouse = u.warehouse, t.production = u.production, t.missing = u.missing; here sqlfiddle example.
Comments
Post a Comment