I would like to know how a new record can be inserted in a table when a condition is met. In SQLlite you can as far as I know, but in MARIADB I can't do it. An example of what I would like to do:
INSERT INTO rubros (nombre) SELECT 'Articulos varios' WHERE nombre != 'Articulos varios' ;
This code is tested and returns the following error:
sql error(1064): Something is wrong in your syntax near "WHERE name != 'Miscellaneous Items'" on line 1
In this case, it would be to enter in the table "Items" the record with the name "Miscellaneous articles" if it does not exist. Namely
INSERT INTO table (value) SELECT * WHERE (Condition) In condition, if it is fulfilled, the record is inserted.
PS: I have tried this answer and it didn't work, I have MariaDB version 10.3.12. The code I used to try to use "EXISTS" is the following code:
INSERT INTO rubros (nombre, descripcion)
SELECT 'Articulos varios', ''
WHERE EXISTS (
SELECT nombre FROM rubros WHERE nombre = 'Articulos varios'
) ;
The error that I get is the following:
sql error(1064): Something is wrong in your syntax near " WHERE EXISTS (SELECT name FROM items WHERE name = 'Miscellaneous Items') " on line 1
From already thank you very much
Try using a FROM in your query, using the table
dual
.This following the logic in this answer .
Shouldn't your query have a from?