This is something I can't find any data on.

I've got two database. Database one has a list in it. Database 2 has a list in it as well. I am needing to delete all the entries from database 1 that database 2 also contains. So if database one had entries 1, 2, and 3, while database 2 had entries 2, 3, and 4, Database 1 would delete rows 2 and 3 while database 2 would still do nothing.

Is this even possible? This would make a system I have built at least 1000% more efficient.

Thank in advance for any help,

Resentful

Recommended Answers

All 2 Replies

When you say databases do you mean 2 tables?

DELETE FROM `table2` WHERE `id` IN (SELECT `id` FROM `table1`)
$con = mysqli_connect('1.2.3.4','user','pass','database');
$Q = "DELETE FROM `table2` WHERE `id` IN (SELECT `id` FROM `table1`)";
if(mysqli_query($con,$Q)){
echo 'entries deleted from table2';
}else{
echo 'delete failed: '.mysqli_error($con);
}

Yes, that's what I meant.

I'll try it out and test it tonight.

Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.