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 |
|
liptonIcedTea
Starting Member
26 Posts |
Posted - 2008-02-27 : 18:59:37
|
| HiI have two tables which I'm combining.Select employeeID as id, startDt as startDate from Table1union allSelect CustomerID as id, startDt as startDate from Table2order by startDtThis works fine, unfortunately, my problem is I only want to display the first latest customer. In a Union All, how do i distinguish whether I'm ordering the table it is trying to union or the actual unioned table tiself? For example, this does not work.Select employeeID as id, startDt as startDate from Table1union allSelect top 1 CustomerID as id, startDt as startDate from Table2order by startDt descorder by startDt |
|
|
LoztInSpace
Aged Yak Warrior
940 Posts |
Posted - 2008-02-27 : 20:49:18
|
| do it as a sub-query. Something likeSelect employeeID as id, startDt as startDate from Table1union allselect * from(Select top 1 CustomerID as id, startDt as startDate from Table2order by startDt desc)order by startDt |
 |
|
|
liptonIcedTea
Starting Member
26 Posts |
Posted - 2008-02-28 : 00:07:20
|
| ThanksYes that's what i ended up doing. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-02-28 : 02:26:51
|
quote: Originally posted by LoztInSpace do it as a sub-query. Something likeSelect employeeID as id, startDt as startDate from Table1union allselect * from(Select top 1 CustomerID as id, startDt as startDate from Table2order by startDt desc) as t order by startDt
MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|