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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:06:28+00:00 2026-06-16T00:06:28+00:00

I am working on a forum system and I need to delete all topics

  • 0

I am working on a forum system and I need to delete all topics and posts from a particular forum.

There is a posts table that holds all the posts. Each post has topic_id field which is the ID of the topic to which it belongs. The topics reside in topics table and each topic has forum_id field which is the ID of the forum it belongs to.

So now when I decide to delete forum with ID 1, how would I go about deleting all topics and posts from this forum as well?

  • 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-16T00:06:29+00:00Added an answer on June 16, 2026 at 12:06 am

    First of all I recommend you take a good look at your data structure: If you use foreign key constraints of the ON DELETE CASCADE flavour, your sub-deletes will automatically be done for you – and this just one of the advantages you get.

    If for some reasons you can’t or don’t want to employ such constraints, start by taking a look at how you would select the relvant topics and posts. This should give you quite a good start.

    In your particular example something like

    DELETE FROM posts
    WHERE topic_id IN (
         SELECT id FROM topics WHERE forum_id=[id-to-delete]
      )
    

    and then

    DELETE FROM topics WHERE forum_id=[id-to-delete]
    

    should do the trick.

    Please understand, that I don’t recommend that. Use data consistency tools for data consistency.

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

Sidebar

Related Questions

I have a View set to grab the latest forum posts. That's working fine,
I have a discussion forum/blog engine working with web forms. Each post contains html
Greetings, Forum. I'm working on a program in Python that uses Twisted to manage
I'm working with a form that I've altered from another site I created, which
Im developing java program ,and I need to make it start working at each
I'm working on WinForms project. I need to change color of my form from
Everything is working up to here, I just need to create the method that
I am using SwiftMailer to send emails from my application. All is working fine
I am working in a Java EE project that integrates with SAP system, and
I'm working with a Web Service that returns an XML string. I need to

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.