Friday, 16 August 2013

Inserting data from one table to the next in sql

Inserting data from one table to the next in sql

I have two tables with fields as shown below :-
tbl_emp --> id(auto generate, auto increment, primary key),name, dob
tbl_login --> id(refers to id in tbl_emp, primary key), password
I have a web form which reads the name, password and date of birth(dob),
and a submit button. On pressing the submit button, the data is inserted
into the first table, and also to the second table. It would be easy to
insert data to the second column if I had a way to access the "id" field
from the first table.
The query I have is :-
insert into tbl_emp (name,dob) values(@name, @dob);
insert into tbl_login (id,password) values((select id from tbl_emp where
id=(select id from tbl_emp where id=id)), @password)
The problem that I encounter with the above coeds is :
Subquery returned more than 1 value. This is not permitted when the
subquery follows =, !=, <, <= , >, >= or when the subquery is used as an
expression.
The statement has been terminated.

No comments:

Post a Comment