Sorry about the Question title, didn't know exactly how to call it...
I have a table called consults:
Name, Last Name, email
And a table called Users:
Name, Last Name, email
I need to copy all the data from the table consults that is not in the table Users (using email). There are repeated emails in the consults table (but not necessary have the same name and last name, although some of them are the same. For example: John - Black - johnblack@mail.com / John - BlackS - johnblack@mail.com. These 2 records are the same, but there was a mistake when the lastName was entered for second time, note the "S").
With the next query I have what I want in part, but I also need the name and last name, and I can't use distinct with all the rows because distinct for some reason returns less records that the ones I know it has to return. I write it clearer.
SELECT DISTINCT Email FROM Consults
WHERE (Email NOT IN (SELECT email FROM users)) <---- with this query I get the records I want (but I also need Name and lastName!). I also know with this how many records I'll have to copy to the other table (it returns 450 records).
If I use SELECT DISTINCT Name, lastName, Email FROM Consults
WHERE (Email NOT IN (SELECT email FROM users))
It returns less records than 450, I think Distinct "groups" using lastname and name too and some rows disappear.
Just to learn more, I would be happy with the query that returns what I want (I was going to paste results in Excel, and then export it to the Users table through SQL Server Manager) and also with a direct Insert, that automatically inserts (adds) the results in the Users table.
I hope you can help me, thanks a lot! :)
Start Free Trial