Error: subquery returning more than one result

Asked

Viewed 1,352 times

2

Given the sql:

DELETE FROM wgcartarmazens
 WHERE (
   SELECT artigo 
     FROM wgcartarmazens as T 
    INNER JOIN wgcartigos as A ON A.CODIGO=T.ARTIGO
    WHERE T.lote='' AND A.TEMLOTE<>0
 );

The above query returns me the following error

subquery Returns more than 1 value this is not permitted when the subquery Follows

How can I correct?

1 answer

4

If you want to make a DELETE in all fields of the subquery, do so:

DELETE FROM wgcartarmazens
 WHERE artigo IN (
   SELECT artigo 
     FROM wgcartarmazens as T 
     JOIN wgcartigos as A ON A.CODIGO = T.ARTIGO
    WHERE T.lote = ''
      AND A.TEMLOTE <> 0
 );
  • @user2478690 our answers are practically the same, but it’s not about opportunism. I only saw your comment after editing the question and posting the answer.

Browser other questions tagged

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