0

I have 3 tables related, and I need to make a Query inside another Query joining them, this is what I got so far:

SELECT a.idarticulo,
       a.idcategoria,
       c.nombre as categoria,
       a.idarticulo,
       a.idsucursal,
       s.nombre as sucursal,
       (SELECT talla.idtalla,
               talla.nombre,
               articulo_talla.idtalla,
               articulo_talla.cantidad,
               articulo_talla.idarticulo,
               articulo.idarticulo,
               articulo.nombre
        FROM talla
               JOIN articulo_talla ON talla.idtalla = articulo_talla.idtalla
               JOIN articulo ON articulo_talla.idarticulo = articulo.idarticulo
        WHERE articulo.idarticulo = a.idarticulo) as tallaCantidad,
       a.codigo,
       a.nombre,
       a.stock,
       a.descripcion,
       a.imagen,
       a.condicion
FROM articulo a
       JOIN categoria c ON a.idcategoria = c.idcategoria
       JOIN sucursal s ON a.idsucursal = s.idsucursal
ORDER BY idarticulo DESC

But it throws me the following error: #1241 - Operand should contain 1 column(s)

Thanks for your help

3
  • Please format your code. It's really hard to make the query out as it is presented here. Commented Sep 11, 2018 at 18:31
  • Hi, and welcome to SO. Please see Why should I provide an MCVE for what seems to me to be a very simple SQL query Commented Sep 11, 2018 at 18:35
  • What part of the error message do you not understand? You have a scalar subquery, but it is returning too many values. It can only return one value. Commented Sep 11, 2018 at 22:13

1 Answer 1

1

Your subselect contains multiple columns. If you need only tallaCantidad :

SELECT a.idarticulo,a.idcategoria,c.nombre as categoria, a.idarticulo,a.idsucursal,s.nombre as sucursal,
(SELECT talla.idtalla, talla.nombre, articulo_talla.idtalla, articulo_talla.cantidad, articulo_talla.idarticulo, articulo.idarticulo, articulo.nombre
FROM talla
    INNER JOIN articulo_talla ON talla.idtalla=articulo_talla.idtalla
    INNER JOIN articulo ON articulo_talla.idarticulo=articulo.idarticulo
    WHERE articulo.idarticulo=a.idarticulo) as tallaCantidad, a.codigo,a.nombre,a.stock,a.descripcion,a.imagen,a.condicion
FROM articulo a
INNER JOIN categoria c ON a.idcategoria=c.idcategoria
INNER JOIN sucursal s ON a.idsucursal=s.idsucursal
ORDER BY idarticulo DESC
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.