We help IT Professionals succeed at work.
Get Started

How to check if a record already exists before inserting a new one

Last Modified: 2015-03-16
I'm looking for a simple clean way to make an MS SQL statement that selects all of column1 and column2 from one table, and inserts them into another table as new records, but only if the values for both column1 and column2 do not already exist in the table the insertion is being attempted on. Essentially, I do not want any duplication of values where the value of either column1 OR column2 must contain a unique value, but both do not need to be unique. Hope this is an easy one. Thanks.
Watch Question
SQL Server Data Dude
Most Valuable Expert 2013
Author of the Year 2015
This problem has been solved!
Unlock 3 Answers and 8 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE