0

我有以下代码来返回我想要的字符串

$sql = "
    SELECT `description` 
    FROM `auctions` 
    WHERE `description` REGEXP '[0-9]{10}'
";

但是我需要为这样的事情运行更新查询

UPDATE `url` 
FROM `auctions_media`
WHERE `url` = "$sql" AND `auction_id` = SomeNumber

我如何匹配表,以便auction_idforauctions表与auction_idinauctions_media表匹配?

我希望代码遍历所有行,从描述中返回字符串,然后将其用于更新查询

4

2 回答 2

1

也不完全确定你在追求什么,但也许是这样的:

UPDATE auctions_media JOIN auctions USING (auction_id)
SET    auctions_media.url = auctions.description
WHERE  auctions.description REGEXP '[0-9]{10}'

或这个:

UPDATE auctions
  JOIN auctions_media
    ON auctions_media.auction_id = auctions.auction_id
   AND auctions_media.url        = auctions.description
SET    ...
WHERE  auctions.description REGEXP '[0-9]{10}'
于 2013-01-20T09:11:26.143 回答
0
于 2013-01-20T08:41:56.547 回答