DELETE IF CONDITION MET IN A COLUMN

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
MYSQL 
 1287  View(s)
Ratings:
Rate this:
Hi Expert!

i have a table like this:

id, senderNumber, blacklist
-----------------------------
1   0835636326   Y
2   0373562343   Y
3   0273646833   Y
and I want to delete automatically if a new inserted row on another table consist anything on senderNumber column above using a BASH Script

I already using this script:

BLOCKLIST="$( mysql -uroot -pabcde smsd -N -s -r -e "SELECT senderNumber FROM blacklist WHERE senderBlock='Y'" | tr '\n' ' ')"
mysql -uroot -pabcde smsd -e "DELETE FROM inbox WHERE senderNumber = '$BLOCKLIST'"
and this the output:

    sh -x /etc/autodelete.sh
+ tr \n  
+ mysql -uroot -pabcde smsd -N -s -r -e SELECT senderNumber FROM blacklist WHERE senderBlock='Y'
+ BLOCKLIST=083808034690 08164853500 
+ mysql -uroot -pabcde smsd -e DELETE FROM inbox WHERE senderNumber = '083808034690 08164853500 '
but no luck. any help would be very appreciated.

Thanks in advance!
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Delete if condition met in a column

    Hi Ankita!

    try this way

    mysql -uroot -pabcde smsd -e "DELETE FROM inbox WHERE senderNumber like =".$BLOCKLIST

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!