There are 2 tables. The first one has fname (first name), lname (last name), and the second has many columns, including: salutation (Mr, Dr, etc.), fname (name), mname (middle name), lname (last name), unique identifier and date.
I want to create a third table containing salutation , fname , mname , lname , uid , added from the information in the other two tables, after which I will delete the first table and recreate the second table by deleting these columns.
This is what I have:
CREATE TABLE MyTable ( Id int IDENTITY (1, 1) PRIMARY KEY, Salutation varchar(20) NULL DEFAULT (NULL), Fname varchar(30) NOT NULL, Mname varchar(30) NULL DEFAULT (NULL), Lname varchar(30) NOT NULL, Uid uniqueidentifier NULL DEFAULT (NULL), Added Date NOT NULL DEFAULT (getdate()) ); INSERT INTO MyTable (Fname, LName) SELECT Fname, Lname FROM TABLE1
This is where I am confused:
INSERT INTO MyTable (Salutation, Fname, Mname, LName, Uid, Added) SELECT Salutation, Fname, Mname, LName, Uid, Added FROM Table2 WHERE Fname, Lname NOT IN (SELECT Fname, Lname FROM Table1)
Can someone fix the last INSERT to make it work?
- he doesn't like
Fname, Lname right of the word WHERE - Should I insert from the second table first, and then from the first?