I'm trying to select items out of the same table, re-organize the data, and then insert data into the same table as new records (basically I'm taking "A" records for DNS and converting them into "PTR" records).

The problem is, I do not want to create the records if three of the columns exist - so basically, if three of the columns all exist (and they all have to exist, because if just one doesn't match, then it should be inserted into the database) then I want to keep MySQL from inserting it.

Here's the table:

```
mysql> describe records;
+-------------+----------------+------+-----+---------+----------------+
| Field       | Type           | Null | Key | Default | Extra          |
+-------------+----------------+------+-----+---------+----------------+
| id          | int(11)        | NO   | PRI | NULL    | auto_increment |
| domain_id   | int(11)        | YES  | MUL | NULL    |                |
| name        | varchar(255)   | YES  | MUL | NULL    |                |
| type        | varchar(10)    | YES  |     | NULL    |                |
| content     | varchar(64000) | YES  |     | NULL    |                |
| ttl         | int(11)        | YES  |     | NULL    |                |
| prio        | int(11)        | YES  |     | NULL    |                |
| change_date | int(11)        | YES  |     | NULL    |                |
+-------------+----------------+------+-----+---------+----------------+
8 rows in set (0.00 sec)

```

The following SQL I was able to get working and it works, just without the checking of the three other fields being "unique":

```
INSERT INTO records (domain_id,name,type,content,ttl,prio,change_date) SELECT domain_id AS domain_id, substring_index(content, '.', -1) AS name, 'PTR' AS type, concat(`name`, '.') AS content, ttl AS ttl, prio AS prio, unix_timestamp() AS change_date from records where type='A'

```

Basically the only thing missing here is that if domain\_id, name, and content ALL exist in another row (based on the current insert), then I want it to skip that single insert and proceed to the next insert, because I do not want the same records in the database.