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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:20:26+00:00 2026-05-15T05:20:26+00:00

I have two tables. table a references table b I believe. When I try

  • 0

I have two tables. table a references table b I believe.

When I try to delete the package alltogether like this:

$query="DELETE a, b FROM classified as a, $sql_table as b WHERE a.ad_id = '$id' 
AND a.classified_id = b.classified_id AND a.poster_password='$pass'";

b MUST be deleted first I guess.
Even in PhpMyAdmin I cant delete a if b is still there, so I delete b first.

But what decides the order in which comes first?

The tables are alla InnoDB.

What should I do?

Thanks

  • 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-15T05:20:27+00:00Added an answer on May 15, 2026 at 5:20 am

    Your Delete syntax is invalid. You need to do this in two statements (unless as nuqqsa mentioned, you have CASCADE DELETE enabled on the relationship between table a and table b):

    Delete From b
    Where Exists    (
                    Select 1
                    From a
                    Where a.poster_password = '$pass'
                        And a.ad_id = '$id'
                        And a.classified_id = b.classified_id
                    )
    
    Delete From a
    Where a.poster_password = '$pass'
        And a.ad_id = '$id'
    

    What decides which comes first is the foreign keys relationships. Whichever table is the parent table must be deleted from last.

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

Sidebar

Related Questions

I have two tables like this: TABLE user( id CHAR(100) text TEXT ) TABLE
I have two tables like this: CREATE TABLE `tblFacilityHrs` ( `id` int(11) NOT NULL
I have two tables built like this (this is just a simplified and non-proprietary
This is the situation: I have two tables where the one references the other
I have a script in MySQL that creates two tables, the second table references
I have a problem with my delete statement. I have two tables: table vehicule_loan(
Good Morning. I have two tables, and one references the other. When I insert
I have two tables: table a ida valuea 1 a 2 b 3 c
I have two tables: Table_A name1 create_date Table_B name2 keep_time name1 is something like
I have two Tables: Table 1: Questions : QuestionId NUMERIC Title TEXT Test Data

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.