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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Where exists

Author  Topic 

gemispence
Yak Posting Veteran

71 Posts

Posted - 2006-02-18 : 09:39:08
I'm trying to perform an insert query on a table, but I also want to check to see if the record exists already in the table. It should be fairly simple, but I'm having a time of it. Should be something like:

select * from users u
inner join miamiherald m
on u.emailaddress = m.advertiseremail
where not u.emailaddress not exists <<< (???)

If it does exist, I then want to retrieve two columns from it. HELP!!

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-02-18 : 09:46:28
something like this
insert into table1(col1, col2, col3)
select cola, colb, colc
from table2 t
where not exists (select * from table1 x where x.col1 = t.cola)

assuming that table1's primary key is col1

----------------------------------
'KH'

Time is always against us
Go to Top of Page
   

- Advertisement -