I have two tables in a master detail layout. I want to select all Active items from the Master Table and detail records only if they meet a condition. But I want all Master table items no matter id a detail record exists or not.
My tables look like: Master - inventoryItem
icmasterid icdescription
WAD110795 WM KIWI-KLIP 3 BEND
WAD110796 WM KIWI-KLIP 3 BEND (MZ3,4,&6)
WAD118806-50 STROLLER VALENCE BACKDRP HINGE
WAD118808 IK STROL B DROP MOUNTING HDW
WAD118942 1" S-HOOK BAG 100
Detail - inventoryLine
icmasterid icdetailquantity pomasterid
WAD110796 -900 NULL
WAD110796 0 NULL
WAD110796 0 119450
WAD110796 900 119347
WAD118808 0 NULL
WAD118808 34 NULL
WAD118942 0 NULL
WAD118942 59 NULL
WAD118942 0 NULL
WAD118942 -59 NULL
WAD118942 59 NULL
my sql
SELECT inventoryitem.icmasterid,
inventoryitem.icdescription,
inventoryline.icdetailquantity,inventoryline.pomasterid
FROM inventoryitem
LEFT OUTER JOIN inventoryline ON inventoryitem.icmasterid=inventoryline.icmasterid
WHERE inventoryitem.icmasterid < 'WAD18' and inventoryitem.icmasterid like 'WAD%'
ORDER BY inventoryitem.icmasterid
The above gives me all items in inventoryitem and their related inventoryline records as expected.
But when I add
and inventoryline.pomasterid <> ''
I get just two rows.
icmasterid ICdescription icdetailquantity pomasterid
WAD110796 WM KIWI-KLIP 3 BEND (MZ3,4,&6) 0 119450
WAD110796 WM KIWI-KLIP 3 BEND (MZ3,4,&6) 900 119347
What I need is
icmasterid icdescription icdetailquantity pomasterid
WAD110796 WM KIWI-KLIP 3 BEND (MZ3,4,&6) 0 119450
WAD110796 WM KIWI-KLIP 3 BEND (MZ3,4,&6) 900 119347
WAD118806-50 STROLLER VALENCE BACKDRP HINGE NULL NULL
WAD118808 IK STROL B DROP MOUNTING HDW NULL NULL
WAD118942 1" S-HOOK BAG 100 NULL NULL