Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi all, I have three tables, namely studentdetails, studentperform, studentinter, each table has studentid as the primary key and each table has more than 700records. Now, I need to create a new table studentmaster with three fields from each table mentioned above. What should I do ? Can we do this in a single query ?
timmy
Master Smack Fu Yak Hacker
1242 Posts
Posted - 2004-08-18 : 01:56:20
You should be able to, but I can't be sure because I haven't got your table design:
SELECT D.Field1, D.Field2, D.Field3, P.Field1, P.Field2, P.Field3, I.Field1, I.Field2, I.Field3 FROM studentdetails D INNER JOIN studentperform P ON D.studentID = P.studentID INNER JOIN studentinter I ON D.StudentID = I.StudentID
but you need to make sure that the tables have a 1-1 relationship with each other or you will get duplicates
vimal
Starting Member
4 Posts
Posted - 2004-08-18 : 02:27:47
Thanks Timmy, That works well. Using the SELECT query you mentioned I am able to get the required records in QA. My requirement is that I should permanently store this set of records in a new table studentmaster. How can I do that ?
timmy
Master Smack Fu Yak Hacker
1242 Posts
Posted - 2004-08-18 : 02:38:16
Simply define the new table, then run an insert statement:INSERT INTO newTable(new table field list, . . ...)SELECT statement from above
vimal
Starting Member
4 Posts
Posted - 2004-08-18 : 03:23:42
Thank You very much Timmy. I have done what I wished to do. Thanks once again.