1

我需要编辑这段代码:

UPDATE favorites SET category='$newcat',subcategory='$newsubcat',
sitename='$newwebsitename',
url='$newwebsiteurl' WHERE email='$email' ORDER BY favoritesid ASC LIMIT 1

添加: 'OFFSET 1' 到最后,但由于 UPDATE 不允许该OFFSET命令,我需要使用 anINNER JOIN添加该部分。但是我只知道在删除单个变量时如何执行此操作,例如:

DELETE a FROM favorites a
INNER JOIN
(
  SELECT favoritesid
  FROM favorites
  WHERE email = '$email'
  ORDER BY favoritesid
  LIMIT 1 OFFSET x

 ) b ON a.favoritesid = b.favoritesid

但是当更新多个变量时,我什至不知道从哪里开始。谁能帮我吗?

4

1 回答 1

0

也许是这样的:

UPDATE favorites A INNER JOIN
(
    SELECT favoritesid FROM favorites WHERE email='$email'
    ORDER BY favoritesid LIMIT x
) B USING (favoritesid)
SET
    A.category='$newcat',
    A.subcategory='$newsubcat',
    A.sitename='$newwebsitename',
    A.url='$newwebsiteurl'
;

这是另一种选择:

UPDATE favorites A
SET
    A.category='$newcat',
    A.subcategory='$newsubcat',
    A.sitename='$newwebsitename',
    A.url='$newwebsiteurl'
WHERE A.favoritesid = 
(
    SELECT MAX(favoritesid) FROM favorites WHERE email='$email'
    ORDER BY favoritesid LIMIT x
);

这些示例假定偏移量为 0。如果您有偏移量,请尝试以下操作:

UPDATE favorites A INNER JOIN
(
    SELECT favoritesid FROM favorites WHERE email='$email'
    ORDER BY favoritesid LIMIT x OFFSET $myoffset
) B USING (favoritesid)
SET
    A.category='$newcat',
    A.subcategory='$newsubcat',
    A.sitename='$newwebsitename',
    A.url='$newwebsiteurl'
;
于 2012-08-02T22:05:05.483 回答