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 |
gems
Starting Member
19 Posts |
Posted - 2007-03-13 : 10:07:45
|
Hi All,I am using SQL Server 2000. I have 3 fields in my table. I want to do distinct on one field but also want to show the remaining two fields in the result. How can I do that?Thanks-G |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-13 : 10:13:12
|
[code]select field1, min(field2), min(field3)from mytablegroup by field1[/code] KH |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-03-13 : 10:30:27
|
why not MAX? Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-13 : 10:35:56
|
OP never specify the requirement and typing min only required one hand. KH |
|
|
gems
Starting Member
19 Posts |
Posted - 2007-03-13 : 11:10:02
|
thanks khtan. that works fine. I am pretty new to this. Can you please explain a little as to how this is working? Thanks again. |
|
|
JohnH
Starting Member
13 Posts |
Posted - 2007-03-13 : 13:47:07
|
Suppose you have values'Bob', 1, 2'Bob', 1, 1You might want to see MIN():'Bob', 1, 1Or you might want to see MAX():'Bob', 1, 2Or you might want to see SUM():'Bob', 2, 3Or you might want to see AVG():'Bob', 1, 1.5Or you might want to see something else entirely. You didn't tell us enough, so khtan gave you something to think about. You need to decide what you want to do with the values in those other two columns.John Hopkins |
|
|
gems
Starting Member
19 Posts |
Posted - 2007-03-13 : 15:55:38
|
Thanks John. I understand that. But all my three fields are text fields. So I just wasn't sure how it would work here. |
|
|
|
|
|
|
|