PA in MYSQL, if not exist update else insert

0

I want to verify if there is not a table_id in my table to insert the dish data, in case there already exists a dish_id that updates the amount.

BEGIN
    IF NOT EXISTS(SELECT _id_plato from pedidocarrito) THEN
    insert into pedidocarrito values(null, _id_cliente, _restaurante, _id_plato, _nombre_plato, _bebida_plato, _costo_plato, _cantidad)
    ELSE UPDATE pedidocarrito SET cantidad = _cantidad where id_plato = _id_plato
END

But I get an error in mysql:

MySQL ha dicho: #1064 - Algo está equivocado en su sintax cerca **'ELSE UPDATE** pedidocarrito SET cantidad = _cantidad where id_plato = _id_plato E' en la linea 4

Any advice?

    
asked by ErickZc 27.05.2018 в 06:14
source

0 answers