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 |
|
godspeedba
Yak Posting Veteran
90 Posts |
Posted - 2009-01-14 : 05:44:16
|
| Doesn't work as I had anticipated.The below doesn't return a distinct list of the column re_desc.This seems to be because the re_id is different, but I havent selected a distinct on that field. I am confused SELECT distinct (re_desc), dbo.tb_room_extra.re_amount, dbo.tb_room_extra.re_amount, dbo.tb_room_extra.re_start, dbo.tb_room_extra.re_end,dbo.tb_room_extra.re_id from tb_room_extra where dbo.tb_room_extra.propertyid = @propertyid |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-01-14 : 05:49:48
|
Since you obviously have duplicate records regarding re_desc, what are the rules for handling them?Which record do you want to display?Are you using SQL Server 2005? Then use thisSELECT re_desc, re_amount, re_start, re_end, re_idfrom (SELECT re_desc, re_amount, re_start, re_end, re_id, row_number() OVER (PARTITION BY re_desc ORDER BY re_id DESC) AS recIDFROM tb_room_extra WHERE propertyid = @propertyid) AS dwhere recid = 1 E 12°55'05.63"N 56°04'39.26" |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-14 : 08:54:05
|
also this if you're using sql 2000 or beforeSELECT t.re_desc, t.re_amount, t.re_amount, t.re_start, t.re_end,t.re_id from tb_room_extra tjoin (select re_desc,max(re_id) AS maxid from tb_room_extra group by re_desc)tmpon tmp.re_desc=t.re_descand tmp.maxid=t.re_idwhere t.propertyid = @propertyid |
 |
|
|
|
|
|
|
|