我试图像这样连接这两个表:
select
T2.*
from
(SELECT DISTINCT DésignationBDC2 FROM pdc2 where BDC3 like '%01|06|02%') AS T1
LEFT JOIN (select DésignationBDC2, COULEUR from pdc2 where Id=60) AS T2 ON T1.DésignationBDC2 = T2.DésignationBDC2
这些表是:
但是,我明白了:
并且您将看到,“DésignationBDC2”的顺序从第一个表中丢失。 我如何避免这种情况?
答案 0 :(得分:2)
您不需要使用子查询即可left join
:
SELECT DISTINCT C2.DésignationBDC2, C22.COULEUR
FROM pdc2 AS C2 LEFT JOIN
pdc2 AS C22
ON C22.DésignationBDC2 = C2.DésignationBDC2 AND C22.ID = 60
WHERE P2.BDC3 like '%01|06|02%'
ORDER BY C2.DésignationBDC2;