I have looked for a way to try this, and so far the bet answer is using the INSERT IGNORE
syntax, but my problem is that I won't be working with the id's.
Is there a way to insert a record into the database only if it doesn't exist, if you don't know the record id?
eg: I want to check if the data in col1
('Hello') doesn't already exist.
INSERT IGNORE INTO table_name (col1, col2) values ('Hello', 1);
Existing record:
+--------------------+
| table_name |
+--------------------+
| id | col1 | col2 |
+--------------------+
| 2 | Hello | 1 |
| | | |