-3

I have table C column names userid (uniqueidentifier), password,email,createdate. Table A has columns userid(uniqueidentifier),Email,Createdate and Table B has column name Password.

What query should i execute to get the results. ?

  • Hello and welcome to StackOverflow. Please read [ask] and the guide how to provide a [mcve] carefully and try to edit your post. :) – Tobias Theel Jan 13 '18 at 11:18
  • SQL Server 2012 – Sharjeel Khan Jan 13 '18 at 11:42
  • Actually i have old database that have table profile. I want all info from old db to new one which was created in SQL Server. But problem is that i have created two tables in newdb. Table A contains userID (UniqueIdenfier),UserName ,Email etc but Table B has the columns UserID(UniqueIdentifier) and Password.. I want some columns from Table Profile to Table A and Some columns for Table B.. – Sharjeel Khan Jan 13 '18 at 11:48

1 Answers1

0

You can use a simple join between your table A and table B on the Primary key USER_ID in a select statement inside your insert script.

Here is an sample script based on the information you provided:

INSERT INTO TABLE_C values (
    select A.USER_ID,
        A.PASSWORD,
        B.EMAIL,
        B.CREATED_DATE,
    from TABLE_A A, TABLE_B B 
    where A.USER_ID = B.USER_ID
)

You can learn more on how to insert from a selected query here or here

hd84335
  • 8,815
  • 5
  • 34
  • 45