Reputation: 1
I have two tables Login table and userinfo table. UserInfo table is primary key(UserId) table and login table is foreign key(UserId) table. So my problem is when i insert data in login table value of userid column should come from Userinfo table and value of other columns of log in table like username and password should be inserted directly . Is it possible in single insert statement.
i did the following but it didnt work
insert into login(Userid,username,password)
values(select max(userid) from userinfo,sumit,sumit123)
Upvotes: 0
Views: 5874
Reputation: 1961
insert into login(Userid,username,password)
values((select max(userid) from userinfo),'sumit','sumit123');
Upvotes: 4
Reputation: 1275
Have you tried using a inner JOIN?
INSERT INTO Insurance (Name) SELECT Employee.Username FROM Employee INNER JOIN Project ON Employee.EmployeeID = Project.EmployeeID WHERE Project.ProjectName = 'Hardwork';
Upvotes: 0
Reputation: 300489
insert into login (Userid, username, password)
select max(userid), 'sumit', 'sumit123'
from userinfo
[Please note: while that is syntactically correct, I probably wouldn't do it that way.]
Upvotes: 2