Can anyone tell me how to use a column from a secondary table in a order by
clause?

----- TBL_A ----
ID int PK NOT NULL
Name Varchar(255)  NULL
SortOrder int DEFAULT(9999) NOT NULL

----- TBL_B ----
ID int PK NOT NULL
Name Varchar(255)  NULL
TBL_A_ID int DEFAULT(0) NOT NULL

---- QUERY ----
SELECT B.*
FROM TBL_B B
WHERE
    ( B.NAME LIKE '%John%' )
        AND
    ( B.TBL_A_ID = TBL_A.ID)
ORDER BY
    TBL_A.SortOrder DESC/ASC

There will be instances where TBL_B will NOT have a record for TBL_A, in
these cases the value of TBL_A_ID will default to 0 - FWIW

I am stumped!

Thanks
Brad
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to