MySQL查询删除

时间:2013-06-13 12:36:14

标签: mysql sql database

我想删除tbl_Billing中的记录,我想在执行此功能时使用LIMIT。请建议是否可以使用INNER JOIN或LEFT JOIN。查询在

下面
DELETE
FROM tbl_Billing
WHERE `aCreated` > '2011-01-09'
AND `aStatus` ='2'
AND `aUserUnique`
IN (

SELECT aUserUnique
FROM tbl_Users AS user
WHERE user.`aBillingRenew` < date_sub( now( ) , INTERVAL 60 DAY )
AND user.aActive =1
  )

1 个答案:

答案 0 :(得分:1)

我得到了答案。我们必须使用EXISTS而不是IN运算符:

DELETE
FROM tbl_Billing
WHERE `aCreated` > '2011-01-09'
AND `aStatus` ='2'
AND EXISTS 
( 
  SELECT aUserUnique
  FROM tbl_Users AS users
  WHERE users.`aBillingRenew` < date_sub( now( ) , INTERVAL 60 DAY )
  AND users.aActive ='1'
)
limit 10