MySQL select and update in one query -


i'm trying select value mysql (total_points) add local variable (new_points) , update total_points in same query, know if possible...

i have.,

cursor = database.cursor()  cursor.execute("""select total_points g_ent e_id =%s , user =%s; update total_points = (total_points + %s)""" ,(e_id, user_name, new_points)) database.commit()     

the issue sql syntax not correct. query should be:

update g_ent  set total_points = total_points + %s e_id = %s , user = %s; 

the full example be:

cursor = database.cursor()  cursor.execute("""update g_ent                    set total_points = total_points + %s                   e_id = %s , user = %s;""",                (new_points, e_id, user_name)) # order of params revised database.commit() 

please note order of query parameters revised.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -