I have got a table called Aliases in my MySQL database.
Looks like this:
------------------
| Id | Alias |
------------------
|1 | 'TabX' |
------------------
|2 | 'TabY' |
...
| | |
------------------
And I need to insert to those tables like this:
INSERT INTO (SELECT Alias FROM Aliases WHERE id=1) (somevalue) VALUES (value);
This doesn't work. Please help.
You can reach it with prepared statements:
SET @alias = (SELECT Alias FROM Aliases WHERE id = 1);
SET @sql = CONCAT('INSERT INTO ', @alias, ' (somevalue) VALUES (value)');
PREPARE stmt1 FROM @sql;
EXECUTE stmt1;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With