PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 11, 2022

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

 October 11, 2022     mysql, php, phpmyadmin     No comments   

Issue

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


Solution

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.



Answered By - Tomalak
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing