简体   繁体   中英

This query assigns a value to all records in the table, but I want to assign the value only to the last record

I have two tables. One is publisher_info and the other one is unique_code . I want to assign the u_code column value from the unique_code table to the publisher_info.u_code column. Instead of assigning the value to last record, the query assigns and updated the value of all records. How can I fix this?

$record = "UPDATE publisher_info 
           SET u_code = (SELECT u_code 
                         FROM unique_code 
                         where unique_code.id = ".mysqli_insert_id($conn).")";

最终我得到了答案,查询最终成功了:$ record =“ UPDATE Publisher_info SET u_code =(从unique_code中选择u_code,其中unique_code.id = Publisher_info.id),其中Publisher_info.id =” .mysqli_insert_id($ conn)。“”;

$ record =“ UPDATE Publisher_info SET u_code =(从unique_code ORDER BY unique_code.id DESC LIMIT 1中选择u_code)”;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM