Subject | Calling all SQL Guru's (How do I add an ORDER BY C.DESCRIPTION to this complex SQL statement?) |
---|---|
Author | M Tuttle |
Post date | 2002-06-09T13:45:16Z |
This SQL statement works great, except the DESCRIPTION column is not in
alpha order. How can I make it this way?
Thanks any pointers.
Mike
SELECT DISTINCT CAST(1 AS SMALLINT) AS SELECTED,
CC.CATALOG_ID,
C.CATEGORY_ID,
C.DESCRIPTION
FROM CATALOG_CATEGORY CC
JOIN CATEGORY C ON C.CATEGORY_ID = CC.CATEGORY_ID
WHERE CC.CATALOG_ID = :CATALOG_ID
UNION
SELECT DISTINCT CAST(0 AS SMALLINT) AS SELECTED,
CC.CATALOG_ID,
C.CATEGORY_ID,
C.DESCRIPTION
FROM CATEGORY C
LEFT OUTER JOIN CATALOG_CATEGORY CC ON CC.CATEGORY_ID = C.CATEGORY_ID
WHERE CC.CATEGORY_ID NOT IN (SELECT CC2.CATEGORY_ID
FROM CATALOG_CATEGORY CC2
WHERE CC2.CATALOG_ID = :CATALOG_ID)
alpha order. How can I make it this way?
Thanks any pointers.
Mike
SELECT DISTINCT CAST(1 AS SMALLINT) AS SELECTED,
CC.CATALOG_ID,
C.CATEGORY_ID,
C.DESCRIPTION
FROM CATALOG_CATEGORY CC
JOIN CATEGORY C ON C.CATEGORY_ID = CC.CATEGORY_ID
WHERE CC.CATALOG_ID = :CATALOG_ID
UNION
SELECT DISTINCT CAST(0 AS SMALLINT) AS SELECTED,
CC.CATALOG_ID,
C.CATEGORY_ID,
C.DESCRIPTION
FROM CATEGORY C
LEFT OUTER JOIN CATALOG_CATEGORY CC ON CC.CATEGORY_ID = C.CATEGORY_ID
WHERE CC.CATEGORY_ID NOT IN (SELECT CC2.CATEGORY_ID
FROM CATALOG_CATEGORY CC2
WHERE CC2.CATALOG_ID = :CATALOG_ID)