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
Post a Comment