We help IT Professionals succeed at work.

How to delete the records fetched by this SQL Query

Medium Priority
319 Views
Last Modified: 2012-08-13
I want to delete records from RULE_PARAMETER_ARCHIVE which are fetched from below query.

      select a.versionid, a.rulesetid, a.rulearchid from RULE_PARAMETER_ARCHIVE a
      inner join
      (
      select versionid, rulesetid, rulearchid
      from RULE_SET_ARCHIVE
      where NOT exists
            (
            select NULL from RULE_SET_ARCHIVE M
            group by VersionId, RuleSetId
            having M.versionid = RULE_SET_ARCHIVE.VersionId
            and M.RuleSetID = RULE_SET_ARCHIVE.RuleSetId
            and max(M.RuleArchId) = RULE_SET_ARCHIVE.RuleArchId
            )
      ) b
      on       a.versionid = b.VersionId
            and a.RuleSetID = b.RuleSetId
            and a.RuleArchId = b.RuleArchId
Comment
Watch Question

Sr Database Engineer
CERTIFIED EXPERT
Commented:
Something like:

DELETE a
FROM RULE_PARAMETER_ARCHIVE a
      inner join
      ( select versionid, rulesetid, rulearchid
      from RULE_SET_ARCHIVE
      where NOT exists
            (select NULL from RULE_SET_ARCHIVE M
            group by VersionId, RuleSetId
            having M.versionid = RULE_SET_ARCHIVE.VersionId
            and M.RuleSetID = RULE_SET_ARCHIVE.RuleSetId
            and max(M.RuleArchId) = RULE_SET_ARCHIVE.RuleArchId)
      ) b   on       a.versionid = b.VersionId
            and a.RuleSetID = b.RuleSetId
            and a.RuleArchId = b.RuleArchId

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
CERTIFIED EXPERT
Awarded 2008
Awarded 2008

Commented:
delete a from RULE_PARAMETER_ARCHIVE a
      inner join
      (
      select versionid, rulesetid, rulearchid
      from RULE_SET_ARCHIVE
      where NOT exists
            (
            select NULL from RULE_SET_ARCHIVE M
            group by VersionId, RuleSetId
            having M.versionid = RULE_SET_ARCHIVE.VersionId
            and M.RuleSetID = RULE_SET_ARCHIVE.RuleSetId
            and max(M.RuleArchId) = RULE_SET_ARCHIVE.RuleArchId
            )
      ) b
      on       a.versionid = b.VersionId
            and a.RuleSetID = b.RuleSetId
            and a.RuleArchId = b.RuleArchId

Author

Commented:
You are going to like this :)... I was trying exact same query since a hour but I was missing "a" in this first line...

DELETE a FROM RULE_PARAMETER_ARCHIVE
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.