0

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

1
  • Instead of DELETE FROM LINPED ..., try DELETE LINPED FROM LINPED ... Commented Jan 1, 2018 at 21:04

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.