0

I am trying to fetch data from multiple table where i have one product with its details distributed in multiple tables. Here is one query i am using:

SELECT 
    fp.id, fp.name, fp.slug, fp.status, fp.approved, fp.created_at, fp.updated_at,
    fc.name as cat_name, fc.slug as category_slug, 
    ff.filepath,
    fdp.type, fdp.sku, fdp.regular_price, fdp.sale_price

FROM `foduu_products` fp 

JOIN `foduu_category_product` fcp 
ON fp.id = fcp.product_id

JOIN `foduu_filemanager` ff 
on fp.filemanager_id = ff.id 

JOIN `foduu_categories` fc 
on fcp.category_id = fc.id 

JOIN `foduu_details_product` fdp 
ON fp.id= fdp.product_id 

where fcp.category_id in (39,155,30,41,51)

group by fdp.product_id           <<<<--------------------  Here is the problem

ORDER by fp.id ASC

When i am using GROUP BY to get data from foduu_details_product where it hold multiple records for one product_id. When i am running this query i am getting this error.

#1055 - Expression #8 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'foduu-ecommerce-cms.fc.name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

Not understanding why GROUP BY always give me these short of errors. Any suggestions how can i improve my query here?

Here is my database tables SQL for reference:

http://vbought.com/products%20table.sql

Thank you (in advance)!

user3201500
  • 1,538
  • 3
  • 22
  • 43

1 Answers1

0

You don't have any aggregate function in your query so you should question the use of this specific statement in the first place.

You are in "sql_mode=only_full_group_by", thus you have to repeat every column in the select that is not use in an aggregate function (Max,Sum,Count...) in the group by statement.

Nerevar
  • 303
  • 1
  • 9