Query with multiple records returns only one record

0

It returns only one record and in my DB there are 3. I suspect that the problem may be in the query, with the theme of concatenating tables.

Here my sentence:

SELECT 
  productos.nombre, 
  productos.name, 
  productos.precio,
  categorias.name as cat_name,
  categorias.nombre cat_nombre,
  SUM(productos.precio) as total_price 
FROM wishlist, productos, categorias 
WHERE wishlist.cod_producto=productos.cod_producto 
  AND productos.cod_categoria=categorias.cod_categoria 
  AND wishlist.cod_user = '$cod_user'
    
asked by marçal Roura 25.05.2018 в 18:08
source

1 answer

0

If you include an aggregate function such as SUM , it is best to use a GROUP BY as well

SELECT 
  productos.nombre, 
  productos.name, 
  categorias.name as cat_name,
  categorias.nombre cat_nombre,
  SUM(productos.precio) as total_price 
FROM wishlist, productos, categorias 
WHERE wishlist.cod_producto=productos.cod_producto 
  AND productos.cod_categoria=categorias.cod_categoria 
  AND wishlist.cod_user = '$cod_user'
GROUP BY
  productos.nombre, 
  productos.name, 
  categorias.name,
  categorias.nombre
    
answered by 25.05.2018 в 18:48