我有一张这样的桌子。
CREATE TABLE `chart` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`item` char(6) NOT NULL DEFAULT '',
`IsLeaf` char(1) NULL DEFAULT 'Y',
`ParentId` int(10) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
)
其中 parentId 包含另一行的 id ,这是该行的父行 Like
-----------------------------------------------------------------
| Id | item | IsLeaf | ParentId
-----------------------------------------------------------------
| 1 | Test1 | D |
-----------------------------------------------------------------
| 2 | Test3 | D |
-----------------------------------------------------------------
| 3 | Test4 | D | 1
-----------------------------------------------------------------
| 4 | Test5 | D | 1
-----------------------------------------------------------------
我想更新那些至少有一个子行的行。我试过这样
UPDATE chart AS c1 SET c1.IsLeaf='Y' JOIN chart c2 ON c2.ParentId=c1.id;
并得到了这个错误
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'JOIN chart c2 ON c2.ParentId=c1.id' at line 1