How to do SQL inner queries through SQLAlchemy?

How do you do multiple SQL Update queries at once?

  • So lets say I have a table called bird, and a table called guitar(please ignore messy syntax). And I wanted to run multiple(hundreds...) SQL update queries on each, all at once using a $_POST php form button. How would I set that up in terms of the php for the multiple SQL updates(I can set up the form button easily)? I've tried doing something like below, but it is really not working well at all. I'm thinking I need to use foreach somehow...maybe? $value= array(); $value[] = array( 'A' => $row['whatever'], 'B' => 'another value ', //and so forth ), array ( 'A' => '1', 'B' => '2', //and so forth... ) $value2= array(); $value2[] = array( 'guitar' => 'old', 'music' => 'new', //and so forth ) $sql = 'UPDATE ' . BIRD_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary); $db->sql_query($sql);

  • Answer:

    UPDATE can only update one sets of fields at a time. For example: UPDATE bird SET name='aaa', color='red' WHERE <expression> You can not update multiple sets of fields with one UPDATE statement: ***wrong*** UPDATE bird SET name='aaa', name='bbb', name='ccc' ***wrong*** So what you are trying to do is not possible. Why do you insist on using only one UPDATE? You should use a loop to go through each record and update them one at a time. And yes this can be all in one POST no matter how many records you need to update. One way to do this is to make their primary key (such as ID) part of the parameter name.

Vipaka at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.