背景:我有一个包含地址列的订单表,我想用从临时表中随机选取的地址更新这些列两个表都包含address、address1、city和postcode列我想查询应该是这样的:
UPDATE orders (address, address1, city, postcode) VALUE (SELECT address, address1, city, postcode FROM addresses ORDER BY RAND() LIMIT 1) WHERE orders.id = 72;
yc0p9oo01#
UPDATE orders JOIN ( SELECT address, address1, city, postcode FROM addresses ORDER BY RAND() LIMIT 1 ) AS newdata SET orders.address = newdata.address, orders.address1 = newdata.address1, orders.city = newdata.city, orders.postcode = newdata.postcode WHERE orders.id = 72;
1条答案
按热度按时间yc0p9oo01#