请教一个update语句怎样写
现在有一张表,字段如下:
id     name    parent_name   parent_id
001    jack      tom
002    tom
数据库现在id、name、parent_name都已经有数据了,但是parent_id还没有,
请问如何用一个update语句,查到parent_id并补上?(就是update上面第一行的parent_id为002).
希望各位高手指教!
              
------解决方案--------------------
update t1 
set parent_id= (select id from  t1 t where t.name = t1.parent_name)
where parent_id is null and parent_name is not null