If one of the table's fields is defined as UNIQUE or PRIMARY KEY, it will
allow the insertion only once with that key.  When a second attempt is made
to insert the record with the same key, the insertion will be ignored and
you may ignore the error code that results.

Would that work for you?

-----Original Message-----
From: Votteler Marc [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, November 14, 2001 11:01 AM
To: [EMAIL PROTECTED]
Subject: INSERT with SELECT on same table


Hi there,

I am currently facing the following problem and hope someone can help me.

I want to make an INSERT into a Table only if I haven't done this before.
This is because the INSERT can be done by several Programs and the record
should only be inserted once.

I have found the following solutions (but none of them was satisfying):

1. First do a SELECT and the make an INSERT if necessary.

2. Doing the following works fine with MS SQL and Oracle but not with mySQL:

   insert into myTable (myCol) 
   select distinct '8888' from myTable
   where '8888' not in (select myCol from myTable );

   The error I get is "ERROR 1066: Not unique table/alias: 'af_events'"

That's it. Hope someone can help me.

Thanks in advance
marc

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to