I couldn't seem to get the right syntax down in order to insert data from one table into another if main_table had an empty value for email. If the main_table email is empty for an id then I would lke to insert the email for that id from the secondary_table:
MariaDB> SELECT * FROM `main_table`;
+------+---------------------+----------------------------------+------+
| Id | Email | Other | More |
+------+---------------------+----------------------------------+------+
| 1 | [email protected] | blah | A |
| 2 | | needs email from secondary_table | B |
| 3 | [email protected] | blah | C |
+------+---------------------+----------------------------------+------+
3 rows in set (0.09 sec)
MariaDB> SELECT * FROM `secondary_table`;
+------+---------------------+-------+
| Id | Email | Info |
+------+---------------------+-------+
| 1 | [email protected] | blah |
| 1 | | blank |
| 2 | [email protected] | blah |
| 2 | | blank |
| 3 | [email protected] | blah |
| 3 | | blank |
+------+---------------------+-------+
6 rows in set (0.09 sec)
In this example id number 2 in the main_table has the email empty. I'm trying to get the id with the email from the secondary_table inserted to the main_table. I've tried:
INSERT INTO `main_table`
(`Email`)
VALUES
( SELECT `Email` FROM `secondary_table` WHERE `Id` IN
( SELECT `Id` FROM `main_table` WHERE `Email` == '') ) ;
And various other failures along the way... maybe it's something simple, but I'm stuck!
idinsecondary_tableis not unique. You need to define which of multiple possible rows you want to use for an update.Id's have a blankEmailvalue underneath. Thanks for your all your great help, it was tremendous for the immediate issue.