Daniel
Daniel

Reputation: 71

SQL ERROR when i try to do a delete from using 2 tables

I'm using MariaDB. Im trying to do a delete using this two tables:

Table LINPED:

CREATE TABLE LINPED (
    NUMPEDIDO SMALLINT NOT NULL,
    NUMLINEA SMALLINT NOT NULL,
    NUMPIEZA CHAR(16),
    PRECIOCOMPRA INTEGER,
    CANTPEDIDA SMALLINT,
    FECHARECEP datetime,
    CANTRECIBIDA SMALLINT);

Table PEDIDO:

CREATE TABLE PEDIDO (
    NUMPEDIDO SMALLINT NOT NULL,
    NUMVEND SMALLINT,
    FECHA datetime);

At first i try to do that:

DELETE FROM LINPED
INNER JOIN PEDIDO 
ON LINPED.NUMPEDIDO = PEDIDO.NUMPEDIDO
WHERE PEDIDO.NUMVEND= 1 AND PEDIDO.NUMPEDIDO= 1

But it not works for me because i get this error:

[Window Title] sesion1: Error

[Content] Error de SQL (1064): 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 'INNER JOIN PEDIDO ON LINPED.NUMPEDIDO = PEDIDO.NUMPEDIDO WHERE numven' at line 2

[Aceptar]

[Footer] Encontrar ayuda acerca de este error


Searching for a solution in Stackoverfolw I found one similar question with this solution:

DELETE FROM LINPED
JOIN PEDIDO ON LINPED.NUMPEDIDO = PEDIDO.NUMPEDIDO
WHERE PEDIDO.NUMVEND = 1 AND PEDIDO.NUMPEDIDO = 1

But it not works, at least for me

[Window Title] sesion1: Error

[Content] Error de SQL (1064): 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 'JOIN PEDIDO ON LINPED.NUMPEDIDO = PEDIDO.NUMPEDIDO WHERE PEDIDO.NUMVEND = 1 AND' at line 2

[Aceptar]

[Footer] Encontrar ayuda acerca de este error

Upvotes: 0

Views: 47

Answers (1)

Kostas Mitsarakis
Kostas Mitsarakis

Reputation: 4747

Delete from LINPED table explicitly using the following:

DELETE l.*
FROM LINPED AS l
INNER JOIN PEDIDO AS p
ON l.NUMPEDIDO = p.NUMPEDIDO
WHERE p.NUMVEND = 1 AND p.NUMPEDIDO = 1

Upvotes: 1

Related Questions