Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert query values from select query

i want to set the value to a insert query from select query ,how to perform this.

insert into t_user (id,user_id) values (1, ) 
where user_id in (select id from user where id=123)

I want to set the value of user_id from select query value ,how to do this in sql?

like image 941
harqs Avatar asked Sep 19 '26 22:09

harqs


2 Answers

Try this:

INSERT INTO t_user (id, user_id)
SELECT 1, id 
FROM user
WHERE id = 123
like image 135
Mahmoud Gamal Avatar answered Sep 21 '26 18:09

Mahmoud Gamal


insert into t_user(id, user_id) select 1, id from user where id=123;
like image 26
psur Avatar answered Sep 21 '26 16:09

psur