MySQL DELETE查询与派生表

时间:2017-08-22 16:16:35

标签: mysql derived-table

美好的一天。

我遇到了MySql删除查询。

基本上我需要删除此SELECT查询的结果:

SELECT radcheck.* FROM
(SELECT
  permanent_users.realm,
  devices.name,
  devices.created,
  TimeDiff(Now(), devices.created) AS TimeDifference
FROM
  permanent_users
  INNER JOIN devices ON devices.permanent_user_id = permanent_users.id
WHERE
  TimeDiff(Now(), devices.created) > '01:30') MySubQuery
  INNER JOIN radcheck ON MySubQuery.name = radcheck.username

任何帮助都会有很大帮助!

谢谢

2 个答案:

答案 0 :(得分:0)

应该是

  delete radcheck from radcheck
  inner join  (SELECT
      permanent_users.realm,
      devices.name,
      devices.created,
      TimeDiff(Now(), devices.created) AS TimeDifference
    FROM
      permanent_users
      INNER JOIN devices ON devices.permanent_user_id = permanent_users.id
    WHERE
      TimeDiff(Now(), devices.created) > '01:30') MySubQuery on MySubQuery.name = radcheck.username

答案 1 :(得分:0)

继续阅读scaisEdge的提示,这是有效的

谢谢!!

delete radcheck from radcheck
  inner join  (SELECT
     permanent_users.realm,
     devices.name,
     devices.created,
     TimeDiff(Now(), devices.created) AS TimeDifference
  FROM
     permanent_users
     INNER JOIN devices ON devices.permanent_user_id = permanent_users.id
  WHERE
     TimeDiff(Now(), devices.created) > '00:05') MySubQuery on MySubQuery.name = radcheck.username;