Bonjour,

Est-il possible et si oui, comment, d'optimiser ce genre de requête qui a pour objectif d'aller chercher pour n articles, parmi n lignes de réception, le dernier prix et quelques autres informations , sur la ligne de réception qui a été réceptionnée le plus dernièrement?
Ce sont les sous-requêtes qui sont chrono-phages mais je ne vois pas comment ne pas les employer pour ne récupérer que la dernière réception.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
select f3.actif,f3.art_cleunik,f3.code,f3.description,f4.der_pa,
DATE_FORMAT(f4.dateheure_der_achat, GET_FORMAT(DATE, 'EUR')) as date_der_achat_clair,
f3.nbdec_prix,f4.dateheure_der_achat,
(SELECT f1.pu FROM _recfou_lignes f1 left join _recfou_entetes f2 on f1.commercial_cleunik=f2.commercial_cleunik where f1.code_interne=f3.code order by f2.dateheureexpedition desc LIMIT 1) as pu,
(SELECT f2.dateheureexpedition FROM _recfou_lignes f1 left join _recfou_entetes f2 on f1.commercial_cleunik=f2.commercial_cleunik where f1.code_interne=f3.code order by f2.dateheureexpedition desc LIMIT 1) as dateheure_reception,
(SELECT DATE_FORMAT(f2.dateheureexpedition, GET_FORMAT(DATE, 'EUR')) FROM _recfou_lignes f1 left join _recfou_entetes f2 on f1.commercial_cleunik=f2.commercial_cleunik where f1.code_interne=f3.code order by f2.dateheureexpedition desc LIMIT 1) as dateheure_reception_clair,
(SELECT f1.commercial_ligne_cleunik FROM _recfou_lignes f1 left join _recfou_entetes f2 on f1.commercial_cleunik=f2.commercial_cleunik where f1.code_interne=f3.code order by f2.dateheureexpedition desc LIMIT 1) as commercial_ligne_cleunik,
 (SELECT f1.commercial_cleunik FROM _recfou_lignes f1 left join _recfou_entetes f2 on f1.commercial_cleunik=f2.commercial_cleunik where f1.code_interne=f3.code order by f2.dateheureexpedition desc LIMIT 1) as commercial_cleunik 
 from _article f3 left join _art_achats f4 on f3.art_cleunik=f4.art_cleunik where 
(SELECT pu FROM _recfou_lignes f1 left join _recfou_entetes f2 on f1.commercial_cleunik=f2.commercial_cleunik where f1.code_interne=f3.code order by dateheureexpedition desc LIMIT 1) is not null AND f3.actif=1 and f3.description like '%%' ORDER BY `description` ASC LIMIT 0, 1000
D'avance, merci pour vos lumières?