Amit Moralwar Amit Moralwar - 1 day ago 3
PHP Question

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).")";

Answer

$record = "UPDATE publisher_info SET u_code = (SELECT u_code FROM unique_code ORDER BY unique_code.id DESC LIMIT 1)";

Comments