UPDATE/DELETE in mysql and get the list of affected row ids?

前端 未结 2 471
一整个雨季
一整个雨季 2020-12-09 11:55

Is there an efficient way to get the list of affected row IDs (not the # of affected rows via PHP\'s mysql_affected_rows(), but the actual row ids that were affected) from a

2条回答
  •  猫巷女王i
    2020-12-09 12:24

    try this, it will return the updated ids as "1,2,3....":

    SET @uids := '';
    UPDATE table_name
       SET some_col= 'some_val'
     WHERE some_col= 'some_val'
       AND ( SELECT @uids := CONCAT_WS(',', @uids, id) );
    SELECT TRIM(LEADING ',' FROM @uids);
    

提交回复
热议问题