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 |
|
mangaug
Starting Member
2 Posts |
Posted - 2009-11-23 : 06:02:52
|
| Hi,Please help me how to make the below two queries into one query statement.Query 1:Select Max(Volume_Type_Ranking_BAV), volume_startdate from tbl_volume Inner Join dbo.TBL_VOLUME_TYPEon tbl_volume.Volume_Type_Id=TBL_VOLUME_TYPE.Volume_Type_IdGroup by tbl_volume.volume_startdateQuery 2:select a.volume_startdate, a.volume_quantity, a.volume_timestamp, a.Volume_Type_Id from TBL_VOLUME a inner join (select volume_startdate, Volume_Type_Id, max(volume_timestamp) max_ts from TBL_VOLUME group by volume_startdate, Volume_Type_Id) b on (a.volume_startdate=b.volume_startdate and a.Volume_Type_Id=b.Volume_Type_Id and a.volume_timestamp =b.max_ts) |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-23 : 07:07:19
|
| Use union all between the two statementsMadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-11-23 : 09:24:47
|
| and make sure you have same number of columns returned by both queries (use NULLs as placeholders for other columns). Also the datatypes of corresponding columns on both queries should be the same. |
 |
|
|
|
|
|