Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 order by desc union order by desc

Author  Topic 

feejaz
Yak Posting Veteran

68 Posts

Posted - 2008-07-01 : 09:40:22
HI ALL,

I HAVE CREATED A QUERY LIKE BELOW AND FOUND ERROR
Incorrect syntax near the keyword 'union'.

select top 1 [Call].*, unit.unitname FROM [Call]
left join unit on [Call].unitid=unit.unitid
where CheckCall.unitid= 5
order by CallDate desc
union
SELECT top 1 [Call].*, unit.unitname FROM [Call]
left join unit on [Call].unitid=unit.unitid
where Call.unitid= 7
order by CallDate desc
BUT WHEN I COMMIT THE FIRST ORDER BY COMMAND THE ERROR IS CLEAR BUT THE RECORD ARE NOT IN DESC ORDER.

ANY HELP.




Navi

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-07-01 : 09:46:39
select top 1 [Call].*, unit.unitname FROM [Call]
left join unit on [Call].unitid=unit.unitid
where CheckCall.unitid= 5
order by CallDate desc
union
SELECT top 1 [Call].*, unit.unitname FROM [Call]
left join unit on [Call].unitid=unit.unitid
where Call.unitid= 7
order by CallDate desc


You only need one ORDER BY. The UNION creates a single set of rows to be returned, so there is only one ordering that you can specify.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page
   

- Advertisement -