2013-07-21 95 views
2

如何從我提供「Tim」(WHERE userName ='Tim')時訂購的產品中刪除userID 00002。不是用戶ID,我非常瞭解它。刪除涉及連接表的行

User Info 
------------------ 
userID | userName 
00001 | Jim 
00002 | Tim 
00003 | Steve 
00004 | Boo 

Product Ordered 
------------------ 
userID | ProductCode 
00002 | p0001 
00002 | p0003 
00001 | p0002 
00003 | p0001 

回答

1
DELETE po.* 
FROM `Product ordered` po 
INNER JOIN `User Info` ui 
    ON ui.userID = po.userID 
WHERE ui.userName = 'Tim' 

應該這樣做。

+0

謝謝!它正在工作 – user2454048

0
DELETE FROM product_ordered 
WHERE userID IN (
    SELECT userID FROM user_info 
    WHERE userName='Tim' 
)