Skip to content
Advertisement

How insert if a row not already exists ? (query)

My tables :

Wrong migration script :

I try insert new row if FirstTable.label == Str Test isn’t already exists but i get an error :

SQL Error [1064] [42000]: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ” at line 4


Update : I know IF/ELSE can only use in procedure/function but I hope we can do something like. Any help will be much appreciate ❤️


‘Paul T.’ Answer : If values can throws SQL errors at insertion (like unique or foreign keys), you can use INSERT IGNORE like bellow.

Advertisement

Answer

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement