我有一个名为Posts的表格如下:
ID ID_parent type ID_parent_old ID_old
11 0 topic 0 1
22 0 topic 0 2
33 0 topic 0 3
44 0 reply 1 0
55 0 reply 2 0
... ... ... ... ...
更新后我会有类似的事情:
ID ID_parent type ID_parent_old ID_old
11 0 topic 0 1
22 0 topic 0 2
33 0 topic 0 3
44 11 reply 1 0
55 22 reply 2 0
... ... ... ... ...
那么,该怎么做?非常感谢你。
答案 0 :(得分:2)
如果我理解你这就是你所需要的:
UPDATE Posts p1, Posts p2
SET p1.ID_parent = p2.ID
WHERE p1.type = 'reply'
AND p2.type='topic'
AND p1.ID_parent_old = p2.ID_old