เขียนคำสั่งใน MySQL แล้วขึ้น Error
Error ERROR 1093 (HY000): You can’t specify target table ‘ชื่อ Table’ for update in FROM clause
นั่นก็เป็นเพราะว่า MySQL ไม่ให้ update จาก Select โดยจาก Table ของตัวมันเอง เช่น
update table_a set status = ‘1’ where fid in (select fid from table_a where fname =’abc’)
ถ้าเขียนแบบนี้จะขึ้น Error ทันทีเพราะว่า มันเรียก Update จาก Select Table ของตัวเอง
วิธีการแก้ไข
update table_a set status = ‘1’ where fid in (
select * from (
select fid from table_a where fname =’abc’
) as table_a_tmp
)
ก็จะไม่ขึ้น Error แล้วครับ


