a Order by question

Last Post 10 Sep 2008 08:12 PM by yangwulong1978. 0 Replies.
AddThis - Bookmarking and Sharing Button
Author Messages
yangwulong1978
New Member
New Member

--
10 Sep 2008 08:12 PM
hi,
I have a T-SQL
select b.DepositID,b.Type ,b.Num,b.Date,b.Account,b.Amount from
(SELECT DepositSubItemTable.DepositID as DepositID, DepositSubItemTable.Type as Type, DepositSubItemTable.Num as Num, DepositSubItemTable.Date as Date, DepositSubItemTable.Account as Account, DepositSubItemTable.Amount as Amount
FROM DepositSubItemTable INNER JOIN
DespositTable ON DepositSubItemTable.DepositID = DespositTable.DepositID

union
SELECT DespositTable.DepositID as DepositID, DespositTable.Type as Type, DespositTable.Num as Num, DespositTable.Date as Date, DespositTable.Account as Account, DespositTable.Amount as Amount
FROM DespositTable INNER JOIN
DepositSubItemTable ON DespositTable.DepositID = DepositSubItemTable.DepositID
) b

I want to group by the b.DepositID then in every group I want to order by Type
but after I do the below t-SQL, it ordered by Type, but the same group's record are not together, there are seperate , Does anyone have any idea what the problem it is ?


select b.DepositID,b.Type ,b.Num,b.Date,b.Account,b.Amount from
(SELECT DepositSubItemTable.DepositID as DepositID, DepositSubItemTable.Type as Type, DepositSubItemTable.Num as Num, DepositSubItemTable.Date as Date, DepositSubItemTable.Account as Account, DepositSubItemTable.Amount as Amount
FROM DepositSubItemTable INNER JOIN
DespositTable ON DepositSubItemTable.DepositID = DespositTable.DepositID

union
SELECT DespositTable.DepositID as DepositID, DespositTable.Type as Type, DespositTable.Num as Num, DespositTable.Date as Date, DespositTable.Account as Account, DespositTable.Amount as Amount
FROM DespositTable INNER JOIN
DepositSubItemTable ON DespositTable.DepositID = DepositSubItemTable.DepositID
) b
group by b.DepositID,b.Type ,b.Num,b.Date,b.Account,b.Amount
order by b.Type



Acceptable Use Policy
---