Simon
Simon

Reputation: 23159

How to count number of deleted rows from one table in delete + join structure?

I use the following query, to delete the rows from two tables

delete 
     itc, ic 
from 
     incoming_tours ic 
join 
     incoming_tours_cities itc on itc.id_parrent = ic.id 
where 
     ic.sale = '5'

How can i get the number of affected rows from ic table? (mysql_affected_rows returns the total count, i need only from one table). (I use MyISAM engines in my tables, that is why i don't use foreign keys here)

Thanks much

Upvotes: 1

Views: 1154

Answers (2)

eusto
eusto

Reputation: 5

You can't use affected_rows for this. I think you can use a session variable in an after delete trigger on ic to count deleted rows.

Upvotes: 0

Tomalak
Tomalak

Reputation: 338406

Count the rows beforehand.

select count(*) as sale_rows from ic where ic.sale = '5'

Do it in a transaction to make sure the table does not change between the SELECT and DELETE commands.

Upvotes: 1

Related Questions