How would I change this query that I am running from my servlet so that it takes out the duplicates of B and R just like it is currently doing, but then also combines E and V and removes their duplicates and orders them by E then V? I can add them together with the following code, but cannot order them separately. Any ideas? The order should be B, R, E, V with B and R unioned and E and V unioned but seperated in the order. Currently it is B and R bunched together followed by E and V bunched together. E needs to come before V.
SELECT DISTINCT
a.itemtype
, c.textid
, c.min
, c.max
, rtrim(c.header) as header
, CASE a.itmlabel
WHEN 'B' THEN 1
WHEN 'R' THEN 1
WHEN 'E' THEN 2
WHEN 'V' THEN 2
END ORDERING_COLUMN FROM
RTC_global.productLibrary.vdepts d
, RTC_global.productLibrary.item a
, RTC_global.productLibrary.text c
WHERE
a.priceapproved = 'Y'
AND d.deptcode = -- tempInt.parseInt(dept[0])
AND d.classcode = -- tempInt.parseInt(classCode[0])
AND d.subcode = -- tempInt.parseInt(subCode[0])
AND a.dept = d.dept
AND a.subdept = d.subdept
AND a.class = d.class
AND a.subclass = d.subclass
AND a.textid = c.textid
AND c.status = 'A' ORDER BY ORDERING_COLUMN
SELECT DISTINCT
a.itemtype
, c.textid
, c.min
, c.max
, rtrim(c.header) as header
, CASE a.itmlabel
WHEN 'B' THEN 1
WHEN 'R' THEN 1
WHEN 'E' THEN 2
WHEN 'V' THEN 2
END ORDERING_COLUMN FROM
RTC_global.productLibrary.vdepts d
, RTC_global.productLibrary.item a
, RTC_global.productLibrary.text c
WHERE
a.priceapproved = 'Y'
AND d.deptcode = -- tempInt.parseInt(dept[0])
AND d.classcode = -- tempInt.parseInt(classCode[0])
AND d.subcode = -- tempInt.parseInt(subCode[0])
AND a.dept = d.dept
AND a.subdept = d.subdept
AND a.class = d.class
AND a.subclass = d.subclass
AND a.textid = c.textid
AND c.status = 'A' ORDER BY ORDERING_COLUMN