Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6578439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:46:16+00:00 2026-05-25T15:46:16+00:00

I have am using a closure table for some page heirarchy. I want to

  • 0

I have am using a closure table for some page heirarchy. I want to be able to delete a page and update the level of the children it leaves.

par child level
1   1     0
1   2     1
2   2     0
1   3     2
2   3     1
3   3     0
1   4     3
2   4     2
3   4     1
4   4     0

Prior to deleting page 3 I’ve attempted to update the levels and then deleteing reocrds for page 3 the goal of such being:

par child level
1   1     0
1   2     1
2   2     0
1   4     2
2   4     1
4   4     0

describing this with a (invalid) suquery like so:

UPDATE tbl_page_structures
SET page_level = page_level - 1 
WHERE
    child IN ( SELECT child FROM tbl_page_structures WHERE par = 3 )
AND page_level != 0;
DELETE ... where par=3 or child=3;

which obviously fails on the update.

Ideally would like to complete in one query but if tmp able is way to go then so be it – performace on this is more important that sweet sql sweetness…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:46:16+00:00Added an answer on May 25, 2026 at 3:46 pm

    Try:

    UPDATE tbl_page_structures
    SET page_level = page_level - 1 
    WHERE
        child IN (SELECT * FROM( SELECT child FROM tbl_page_structures WHERE par = 3 ))
    AND page_level != 0;
    DELETE ... where par=3 or child=3;
    

    As @Mark said:

    Currently, you cannot update a table and select from the same table in a subquery.

    Source: http://dev.mysql.com/doc/refman/5.5/en/update.html

    But you can if you do the inner select in a sub-sub-query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL database holding hierarchical data using the Closure Table method. A
I currently have a closure table used for hierarchical data that has 5 million
Using the clojure jdbc library with postgresql. I have a table xxx with a
Anyone have any experience of using Closure js lib and Mootools in the same
I have a JavaScript object that does something like this - using a closure
I have a table relating records using the adjacency list method (table A ),
I'm using closure templates and I can't figure out how to have one main
I have using the following code for developing tabs. $(document).ready(function() { $('#container-1').tabs(); } ....
i have using aqua data studio to run my query from sql server 2005.
We have been using CruiseControl for quite a while with NUnit and NAnt. For

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.