2

当我提供“Tim”(WHERE userName = 'Tim')时,如何从订购的产品中删除用户 ID 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
4

2 回答 2

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

那应该这样做。

于 2013-07-21T16:25:07.553 回答
0
DELETE FROM product_ordered
WHERE userID IN (
  SELECT userID FROM user_info
  WHERE userName='Tim'
)
于 2013-07-21T16:25:51.907 回答