Page is a not externally linkable
- Code, Content, and Presentation
-- Databases
---- sql parent and child categories order with hierarchy


arms - 1:14 pm on Sep 15, 2011 (gmt 0)


Try this as a 2 columkn result



SELECTtype, Spare
FROM
(SELECTDISTINCT advertiser_types.type,' ' AS Spare, advertiser_types.id, 1 as ord
FROMadvertiser_types INNER JOIN advertiser_types AS advertiser_types_1
ONadvertiser_types.id = advertiser_types_1.parent_id

UNION ALL

SELECT'-' AS Spare, advertiser_types_1.type, advertiser_types_1.parent_id, 2 as ord
FROMadvertiser_types INNER JOIN advertiser_types AS advertiser_types_1
ONadvertiser_types.id = advertiser_types_1.parent_id
) s
ORDER BY id, ord

(Did this in MSSqlserver so syntax may vary slightly)


Thread source:: http://www.webmasterworld.com/databases_sql_mysql/4334865.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com