PHPLover
PHPLover

Reputation: 12957

How to resolve this error "MySQL Error: 1109 (Unknown table 'table_name' in MULTI DELETE)"?

I'm using PHP and MySQL(Server version: 5.5.31-0ubuntu0.12.04.2) for my website when I run the following query it's giving me the above error. I couldn't get any clue behind this error. Can anyone help me in resolving this error and suggesting the changes if any to my existing query? For your reference I'm writing my query below:

DELETE
   ABC.theory_sheet_set,
   ABC.theory_sheet_questions
FROM
   ABC.theory_sheet_set AS theory_sheet_set,
   OCN.theory_sheet_questions AS theory_sheet_questions
WHERE
   theory_sheet_set.theory_sheet_set_id = theory_sheet_questions.theory_sheet_set_id
   AND theory_sheet_set.theory_sheet_id=".$theory_sheet_id

The error it gives is as follows:

MySQL Error: 1109 (Unknown table 'theory_sheet_set' in MULTI DELETE)
Session halted.

My database name is ABC. Actually all the table names are valid and all the tables involved in this query are present there into the database. Can you please help me in resolving this issue?

Upvotes: 1

Views: 15749

Answers (2)

PHPLover
PHPLover

Reputation: 12957

If you use the alias names used later into the query at the beginning of of query(i.e. right after the word DELETE) then it will work finely. The only issue there was that it couldn't be able to identify the table from your database as you have used alias names to refer those tables into your database. So in order to remove this bug you must use alias name s you used in the query after DELETE. The rectified query will look like following:

DELETE theory_sheet_set, theory_sheet_questions FROM ABC.theory_sheet_set AS theory_sheet_set, ABC.theory_sheet_questions AS theory_sheet_questions  WHERE theory_sheet_set.theory_sheet_set_id=theory_sheet_questions.theory_sheet_set_id AND  theory_sheet_set.theory_sheet_id="$theory_sheet_id

Upvotes: 3

Low Chee Mun
Low Chee Mun

Reputation: 610

there are syntax error, try on this

DELETE *
FROM
theory_sheet_set theory_sheet_set
INNER JOIN 
theory_sheet_questions theory_sheet_questions ON  
theory_sheet_set.theory_sheet_set_id = theory_sheet_questions.theory_sheet_set_id
WHERE theory_sheet_set.theory_sheet_id=".$theory_sheet_id

Upvotes: 0

Related Questions