Error group by clause postgresql

Hi i got the following query

select products.id,v.id as variation_id,products.name as Nombre,c1.name as Categoria,b.name as Marca,tax_rates.name as Impuesto,SUM(COALESCE(vld.qty_available,0)) as Stockactual,MAX(v.sell_price_inc_tax) as PrecioVenta,MIN(v.sell_price_inc_tax) as min_price,MAX(v.dpp_inc_tax) as max_purchase_price,MIN(v.dpp_inc_tax) as min_purchase_price,products.sku as SKU,products.product_custom_field1 as Numeroserie, products.product_custom_field2 as MAC,products.image,products.enable_stock as Estado,units.actual_name as unit,products.enable_stock as enable_stock,products.created_at

FROM products

LEFT JOIN brands b
ON products.brand_id = b.id

JOIN units
ON products.unit_id = units.id

LEFT JOIN categories as c1
ON products.category_id = c1.id

LEFT JOIN tax_rates
ON products.tax = tax_rates.id

JOIN variations as v
ON v.product_id = products.id

LEFT JOIN variation_location_details as vld
ON vld.variation_id = v.id

GROUP by products.id

and this is the error:

*** error:"column "v.id" must appear in the GROUP BY clause or be used in an aggregate function"**

im migrating from mysql to postgresql

Add it to the GROUP BY statement like below

GROUP by products.id, v.id

1 Like

ty