SQL Select Puzzle
-
All, I have the following table: CREATE TABLE X ( ID tinyint NOT NULL, PARENT_ID tinyint NOT NULL, CONSTRAINT X1 PRIMARY KEY (ID) ) go How can I write a select on it which order rows such that, a row with a particular ID appears BEFORE a row which has the same value for PARENT_ID?
cheers, Neil
-
All, I have the following table: CREATE TABLE X ( ID tinyint NOT NULL, PARENT_ID tinyint NOT NULL, CONSTRAINT X1 PRIMARY KEY (ID) ) go How can I write a select on it which order rows such that, a row with a particular ID appears BEFORE a row which has the same value for PARENT_ID?
cheers, Neil
Does this give you what you're after?
select *,case when parent_id is not null
then parent_id - .5
else id end as OrderByField
from x
order by OrderByField--EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters