Update Query with select for Procedure

2

I'm trying to do a query that will enter a procedure but I'm not having success, the query looks like this:

UPDATE 
  sca_lotacao AS t0 
SET 
  t0.ativo = 0 
WHERE (
    SELECT * 
    FROM 
      sca_pessoa AS t1
      RIGHT JOIN sca_lotacao AS t2 ON t1.idLotacao = t2.idLotacao
    WHERE 
      t1.matricula IS NULL);

Error:

Operand should contain 1 column(s)

I know there must really be something wrong, but I'm trying to figure it out. In SELECT I make to make the selection of all the fields of the Loan that does not have registration and assign them the value of 0 (inactive), but I do not know if this logic is very well.

From what I can see, I can bring all the stockings that nobody has.

    
asked by anonymous 08.12.2014 / 19:03

1 answer

1

If your intention is to update all fields where records exist that meet this condition, you should use the EXISTS

UPDATE 
  sca_lotacao AS t0 
SET 
  t0.ativo = 0 
WHERE 
  NOT EXISTS(
    SELECT * 
    FROM sca_pessoa AS t1 
    WHERE t1.idLotacao = t0.idLotacao);
    
08.12.2014 / 19:12