Delete in sql - Inner Join

Asked

Viewed 878 times

0

As is the syntax of a query using Inner Join delete in sql, to compare two table code and exclude being equal?

Table itemVenda. in table itemvenda a sale was registered whose code is 4. To execute the chargeback, if applicable, the user can remove.

inserir a descrição da imagem aqui

Table controleCaixa. When reversing, the itemvenda table record will be removed and at the same time removed, the record whose codDoc = 4. This document code is generated when the sale is completed.

inserir a descrição da imagem aqui

  • use a sub-select

  • post the structure of your tables and the query you need to help you

  • Follow the table structure. I need a query using Inner Join delete in sql, to compare two table code and exclude be equal.

  • @Joshua: Is the database manager Mysql or SQL Server? Both tags are set. // Is it only one sale item or all sale? // In addition to the tables itemVenda and controleCaixa, there is the table venda?

  • Jose, there’s the sale table too. In this case I managed to solve by blocking an item of sale and delete, the register of the control of the box leaving, only the record in the sale table. I resolved with Rovann’s help below. Thank you!

1 answer

1

In your situation, the recommended would be a FK with Cascade on delete, the bank will take care of doing this.

But still if you’re not going to use the bank’s resources, at the helm, I imagine you’re going to perform something like:

"Delete from Vendas where Codigo = 4;"

Therefore, you should execute the following commands:

Delete from controleCaixa where codDoc = 4;
Delete from itemVenda where venda =4;
Delete from venda where codigo = 4;

all in the same transaction.

  • 1

    Rovann, in this case I managed to solve by reversing an item of sale and deleting, the register of the control of the box leaving, only the record in the sale table. Solved using Delete from controlCaixa Where codDoc = 4; Thanks!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.