View Full Version : Select distinct from left join

29 Feb 2012, 03:01 AM
I have query but i got problem in data which I need to DISTINCT.
here is my query:

SELECT p.PCODE, p.min_lot, p.max_lot, kd.LOT_CODE, kd.wip_chemicalweighing, kd.wip_compounding, kd.wip_extrusion, kd.wip_forming,
kd.wip_deflashing, kc.count_wip_chemical_weighing, kc.count_wip_compounding, kc.count_wip_extrusion, kc.count_wip_forming,
kc.count_wip_deflashing, kc.kanban, kc.virtual FROM (SELECT DISTINCT PCODE, min_lot, max_lot FROM plan) AS p
LEFT JOIN (SELECT LOT_CODE, PCODE, wip_chemicalweighing, wip_compounding, wip_extrusion, wip_forming,
wip_deflashing FROM kanban_data ORDER BY PCODE) AS kd ON (p.PCODE = kd.PCODE)
LEFT JOIN (SELECT DISTINCT PCODE, count_wip_chemical_weighing, count_wip_compounding, count_wip_extrusion, count_wip_forming,
count_wip_deflashing, kanban, virtual FROM kanban_checker ORDER BY PCODE) AS kc ON p.PCODE = kc.PCODE;
I need to distinct data FROM tables plan and kanban_checker.
Thank you..