-
insert into table, select from same table (same info, but key is different)
Hi,
I have two dependant tables, EMPtbl and BenfTbl. Both Emptbl and BenfTbl are joined by username.
Emptbl contains below fields:
UserName (PK)
Enrolled program
BenfTbl fields are:
UserName (FK to Emptbl.username)
BenifitType
Cost
.
.
I need to insert a few new user names after some existing users( Their new user names are different, but all their benifit info remains the same). For example, I have john with all his benift data, I need to insert john1 as new username but have all john benifit info). How would you do that?
Sam
-
Since I am not sure what database or version you are using, I can't be sure, but this should work if your database allows it:
Insert into Emptbl
select 'john1', EnrolledProgram
From Emptbl
Where UserName = 'john'
;
Insert into BenfTbl
Select 'john1, BenifitType, Cost, etc.
From BenfTbl
Where UserName = 'john'
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|