Subject Re: [ib-support] Calling all SQL Guru's (How do I add an ORDER BY C.DESCRIPTION to this complex SQL statement?)
Author Helen Borrie
At 08:45 AM 09-06-02 -0500, you wrote:
>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)

ORDER BY 4

cheers,
heLen


All for Open and Open for All
Firebird Open SQL Database · http://firebirdsql.org ·
http://users.tpg.com.au/helebor/
_______________________________________________________