| Author |
Topic |
|
osullivj
Starting Member
4 Posts |
Posted - 2011-06-17 : 11:20:48
|
| Ok..This should be easy but I cant figure it, I have the following tableID,Name,Address1,Tom,Main Street2,Tom,Main Street3,Tom,Main Street4,Tim,Main Street5,Jane,Main Street6,Jane,Main StreetI would like to get back only the unique records based on name and address taking the first id i.e.1,Tom,Main Street4,Tim,Main Street5,Jane,Main StreetAny ideas?As our society gets more complex and our people get more complacent, the role of the jester is more vital than ever before. Please stop sitting around. We need you to make a ruckus. Seth Godin - Linchpin |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-06-17 : 11:26:54
|
| selecy id = min(id), name, addressfrom tblgroup by name, addressselect id, name, address from(select *, seq = row_number() over (partition by name, address order by id)from tbl) awhere seq = 1==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
osullivj
Starting Member
4 Posts |
Posted - 2011-06-17 : 12:32:40
|
| OK What if I have a value column that I need to take into accountID,Name,Address,Amount1,Tom,Main Street,12,Tom,Main Street,43,Tom,Main Street,14,Tim,Main Street,25,Jane,Main Street,36,Jane,Main Street,3I would like to get back only the unique records based on name and address and value taking the correct id i.e.2,Tom,Main Street,44,Tim,Main Street,25,Jane,Main Street,3As our society gets more complex and our people get more complacent, the role of the jester is more vital than ever before. Please stop sitting around. We need you to make a ruckus. Seth Godin - Linchpin |
 |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-06-17 : 12:36:37
|
| select id, name, address, valuefrom(select *, seq = row_number() over (partition by name, address order by value desc, id)from tbl) awhere seq = 1==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|