# 1241 - Operand should contain 1 column (s)


I have 2 tables one with the general data of Routes and another of Inscriptions of each partner, I want to update the table Routes with the sum of two fields of the table of Registrations and I get the error:


# 1241 - Operand should contain 1 column (s)

This is the code:

UPDATE Rutas set socios = sisocios,
                 no_socios = nosocios
WHERE codigo_ruta = (select x.numconv, 
                            SUM(x.numsocios) as sisocios, 
                            SUM(x.numinvitados) as nosocios
                     FROM inscripcion x
                     where x.situac = 'A'
                     group by x.numconv)
asked by Econed 15.06.2018 в 01:40

1 answer


I have found the problem: when using the equal operator (=), you must ensure that only a single row is returned, otherwise the database will not know with what value to compare. If you want to return more than one row, you should use the IN operator. The solution is to limit the values returned to a single one, and the number of rows to a single one (or change the operator to an IN).

The comment made me put it another way and it has already been resolved, it ended up like this:

SET    socios = (
                     SELECT   SUM(x1.numsocios)
                     FROM     inscripcion x1
                     WHERE    x1.numconv = K.codigo_ruta
                          AND x1.situac ='A'
                     GROUP BY x1.numconv
       no_socios = (
                     SELECT   SUM(x2.numinvitados)
                     FROM     inscripcion x2
                     WHERE    x2.numconv = K.codigo_ruta
                          AND x2.situac ='A'
                     GROUP BY x2.numconv
answered by 15.06.2018 в 15:36