Here's the problem. I have a MySQL database that looks a little like this:
Table: db1.group_a
-----------
| name |
-----------
| Alice |
| Charlie |
-----------
Table: db2.group_b
----------
| name |
----------
| Debbie |
| Bob |
----------
(Yes, each table is in different databases. Also, the actual tables have similar but different structures, I just use one column for simplicity.)
Each name
occurs only once in both databases.
Now what I need to do, is find a row (for example, Bob) and delete it from whichever table it's in. I'm thinking of deleting from group_a
and then checking for affected row(s) and then doing some sort of if (affected_row < 1) { try_in_next_table(); }
in php.
But it would be ideal to do this entirely in MySQL. Is there anyway to accomplish this?