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 |
|
dcarva
Posting Yak Master
140 Posts |
Posted - 2011-07-14 : 14:34:21
|
| Hello,I have the following data:ID Name Location1 test1 area12 test1 area13 test1 area14 test2 area25 test2 area2I am trying to write a sql statement that will return only the first distinct name and location, regardless of ID. But I still need to return at least one id. Example results:1 test1 area14 test2 area2I can do this by using table variables and looping to only insert the records I want. But it would save me a lot of time if I could just use a sql statement.Any help is appreciated! |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-07-14 : 14:48:22
|
Would this work for you?select MIN(Id) as Id, Name, Locationfrom YourTablegroup by Name, Location |
 |
|
|
dcarva
Posting Yak Master
140 Posts |
Posted - 2011-07-14 : 14:51:37
|
| WOW! that's it! I cannot believe I missed that. I was trying all kinds of things. Many thanks! |
 |
|
|
|
|
|