Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting Duplicates or Conditional Insert?

Status
Not open for further replies.

countdrak

Programmer
Jun 20, 2003
358
US
I wrote a INSERT SELECT query. Here is it

INSERT INTO Table1(PosID,EventID,IUser)
SELECT 93,eventid,IUser
from Table1
where posid = 92

92,93 will be coldfusion variables in my ACTUAL code. Here is my question, When I insert a new record, Say I insert

PosID EventID IUser
93 4 234

If 93 , 4 already exsist, I dont want to insert it. Is there a way to do a conditional INSERT SELECT. OR after inserting it, is there a way to delete duplicates?
 
You may try something like this:
INSERT INTO Table1(PosID,EventID,IUser)
SELECT 93,eventid,IUser
from Table1 A
where posid = 92
and not exists (select * from Table1 B where B.posid=93 and B.eventid=A.eventid)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top