P粉9808152592023-08-25 14:47:08
Try this
INSERT INTO db_example.tab_example (id,name,surname) SELECT id,first_name,'M. Nega' FROM db_contacts.tab_mygroup
You can use join in the FROM clause. It should work!
P粉3735968282023-08-25 11:19:31
Simply return the literal value from the SELECT statement; add an expression to the SELECT list. For example:
INSERT INTO db_example.tab_example (id,name,surname,group) SELECT ID , first_name , last_name , '1' AS group FROM db_contacts.tab_mygroup;
Follow-up
Q: Can I use the AS function to select first_name and last_name in the same column? Or do I need another function?
Answer: If you want to combine the values of first_name
and last_name
into a single column, you can join them using an expression and Use this expression in the SELECT list, such as
CONCAT(last_name,', ',first_name')
or
CONCAT(first_name,' ',last_name)The
AS
keyword has no effect in the context of INSERT ... SELECT
, but assigns the expression an Aliases may help future readers.
INSERT INTO db_example.tab_example (id,name,surname,group,full_name) SELECT ID , first_name , last_name , '1' AS group , CONCAT(first_name,' ',last_name) AS full_name FROM db_contacts.tab_mygroup