Let's say I have this table
ID | Name | Hobby
---------------------------
1 | Alex | fishing
2 | Alex | soccer
3 | Nick | bike
4 | George | hike
ID
- is unique. Hobby
- is NOT unique (need to keep it as non-unique)
Inserting a record:
INSERT INTO my_table (ID, Name, Hobby) VALUES ('5', 'Christina', 'bike')
How to modify the query, if I need to insert the record if bike
value does not exist at all in Hobby
column?
Anotherwords:
VALUES ('5', 'Christina', 'bike')
- would NOT be inserted as3 | Nick | bike
existsVALUES ('5', 'Christina', 'cooking')
would be inserted ascooking
is not present inHobby
column at all.
Having existing database with thousands of records, there is a risk that there are duplicates already in Hobby...
But from now on.. when adding new records, I want to avoid adding if already exists..
Thank you.