Reputation: 353
I have two table category and subcategory
I am trying to delete record from this table using mysql
query
Query is=
$sql="Delete t1, t2 From category as t1
INNER JOIN subcategory as t2 on t1.c_id = t2.c_id
WHERE t1.c_id='$del_c_id' ";
This query only delete row from category(t1) whose primary key used into subcategory(t2) table.
Not delete row from category(t1) whose primary key not used in subcategory(t2).
Upvotes: 0
Views: 356
Reputation: 3200
You need to use a LEFT JOIN instead of INNER JOIN. By definition LEFT JOIN returns all results from t1, even if they don't have a match in t2.
See this link for more info on join types: http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html
Upvotes: 2