I have this query in MySQL for retrieving sales data from Dolibarr MySQL database:
What its doing is to link Customer Orders with shipping to get sales by location-:
SELECT DISTINCT c.date_commande as c_date_commande, c.ref, p.ref as p_ref, p.label as p_label, cd.total_ht as cd_total_ht, cd.total_ttc as cd_total_ttc, w.label
FROM llx_societe as s
LEFT JOIN llx_c_departements as d ON s.fk_departement = d.rowid
LEFT JOIN llx_c_country as co ON s.fk_pays = co.rowid, llx_commande as c
left join llx_element_element as el on c.rowid = el.fk_source
left join llx_expedition as e on e.rowid = el.fk_target
left join llx_expeditiondet as sd on sd.fk_expedition = e.rowid
left join llx_entrepot w on w.rowid = sd.fk_entrepot
LEFT JOIN llx_projet as pj ON c.fk_projet = pj.rowid
LEFT JOIN llx_user as uc ON c.fk_user_author = uc.rowid
LEFT JOIN llx_user as uv ON c.fk_user_valid = uv.rowid
LEFT JOIN llx_commande_extrafields as extra ON c.rowid = extra.fk_object , llx_commandedet as cd
LEFT JOIN llx_commandedet_extrafields as extra2 on cd.rowid = extra2.fk_object
LEFT JOIN llx_product as p on cd.fk_product = p.rowid
LEFT JOIN llx_product_extrafields as extra3 on p.rowid = extra3.fk_object
WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_commande AND c.entity IN (1)
order by p.label
It returns duplicate customer orders can anyone help? What would be a better query