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.
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 ERRORIncorrect 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.unitidwhere CheckCall.unitid= 5order by CallDate descunionSELECT top 1 [Call].*, unit.unitname FROM [Call]left join unit on [Call].unitid=unit.unitidwhere Call.unitid= 7order 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.- Jeffhttp://weblogs.sqlteam.com/JeffS |
 |
|
|
|
|