Linked Questions

Popular Questions

SQL JOIN, GROUP BY on four tables not working

Asked by At

Help with the request, I need to group this work request by the materials.id column. Now, adding the last line displays an error. How to do it right?

SELECT materials.sname, materials.id, records.id, usematerials.sell_price, usematerials.material_count, clients.sname, records.sdate, usematerials.material_discount, (usematerials.sell_price*usematerials.material_count) as sell_total_price
FROM materials INNER JOIN
     (usematerials INNER JOIN
      (records INNER JOIN
       clients
       ON records.id_client = clients.id
      )
      ON usematerials.id_record = records.id
     )
     ON materials.id = usematerials.id_material
ORDER BY materials.id GROUP BY materials.id <- not working

Error: Your query does not contain the specified expression "sname" as part of an aggregate function.

Structure: materials, usematerials, records, clients

Related Questions