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 8857787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:40:39+00:00 2026-06-14T14:40:39+00:00

I have one function that I am not happy with, the function deletes a

  • 0

I have one function that I am not happy with, the function deletes a product from a table.

This also then deletes all categories, tags and variants of that product,
and for each variant deletes all its images, documents, and values.

This comes down to two select queries and six delete queries.

Is there a way I could make this less database intensive?

delete from $this->table where id = $id
delete from $this->clink where product_id = $id
delete from $this->tlink where product_id = $id

$variants = select id from $this->vlink where product_id = $id //e.g. (1,2) 

delete from $this->vlink where product_id = $id
delete from cart_variant_values where variant_id in $variants
delete from cart_variant_images where variant_id in $variants
delete from cart_variant_documents where variant_id in $variants

I was hoping I could do something like:

variants = select id from $this->vlink where product_id = $id //e.g. (1,2) 

delete from $this->table where id = $id
delete from $this->clink, $this->tlink, $this->vlink where product_id = $id
delete from cart_variant_values, cart_variant_images, cart_variant_documents  
where variant_id in $variants

But obviously that doesn’t work!


Edit (21 Nov 2012):

Would this work?

DELETE vi, vv, vd, v, p, pc, pt
FROM cart_variant_images vi 
INNER JOIN cart_variant_values vv 
INNER JOIN cart_variant_documents vd 
INNER JOIN cart_product_variants v ON vd.variant_id = v.id
INNER JOIN cart_products p ON v.product_id = p.id
INNER JOIN cart_products_categories pc ON p.id = pc.product_id
INNER JOIN cart_products_tags pt ON p.id = pt.product_id
WHERE p.id = $id;

That query throws me no errors, but I am wondering if it will do what I want?

Note that there will be different amounts of rows in each table, so is inner join the right join?

  • 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-06-14T14:40:41+00:00Added an answer on June 14, 2026 at 2:40 pm

    Use foreign keys with ON DELETE CASCADE

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

Sidebar

Related Questions

I have this function that switches the HTML contents from one element on a
So I am baffled by this one. I have a function that is responsible
I have one javascript function that used to display the menu and content in
I have one function ParseHtmlTable(string htmlContent) . Now in that function I want to
I have a function that performs a monthly task on one or more specified
I have one method that opens a file and passes off to another function
I have a function that, when the user selects one or more items, it
I have the following function that is supposed to trigger anytime one of the
I have one array. I want that array to retain its value between function
I have a win form that creates a site in IIS7. One function needs

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.