yanti Posted March 26, 2012 Share Posted March 26, 2012 Hi, I had this problem which deleting data within 2 different database. My code is below: SELECT b.* FROM 33080_cdr.mt_1201 a INNER JOIN mot.mot9_member_on b ON a.mobile_no=b.mobile WHERE a.dn_status='psanumberbarred' this will select all the data that i want to delete. please help me how to delete the selected result. thank you Quote Link to comment https://forums.phpfreaks.com/topic/259722-delete-data-with-multiple-database/ Share on other sites More sharing options...
cpd Posted March 26, 2012 Share Posted March 26, 2012 Clarification needed. Do you want to delete everything in both tables where there is a matching status of 'psanumberbarred'? Or only data from the `b` table? Moreover, the statement you require is "DELETE FROM" not "SELECT". Quote Link to comment https://forums.phpfreaks.com/topic/259722-delete-data-with-multiple-database/#findComment-1331157 Share on other sites More sharing options...
yanti Posted March 27, 2012 Author Share Posted March 27, 2012 yes, i would like to delete data from 'b' table only. i had used delete from but it gives me an error saying that there is no db selected. tq Quote Link to comment https://forums.phpfreaks.com/topic/259722-delete-data-with-multiple-database/#findComment-1331441 Share on other sites More sharing options...
cpd Posted March 27, 2012 Share Posted March 27, 2012 Provided you have no referential integrity you can do something similar to the following. DELETE b FROM mot.mot9_member_on b INNER JOIN 33080_cdr.mt_1201 a ON a.mobile_no=b.mobile WHERE a.dn_status='psanumberbarred' Consider renaming your databases, tables and fields with more descriptive titles as well. Currently, it is very elusive and unmemorable. Quote Link to comment https://forums.phpfreaks.com/topic/259722-delete-data-with-multiple-database/#findComment-1331719 Share on other sites More sharing options...
yanti Posted March 28, 2012 Author Share Posted March 28, 2012 hi, i had tried your delete query, its works finally...it just that i need to select the table that i want to, then after i can run the delete statement there...how can i miss that simple things... thanks again... tq Quote Link to comment https://forums.phpfreaks.com/topic/259722-delete-data-with-multiple-database/#findComment-1331791 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.