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 |
|
Stalknecht
Starting Member
22 Posts |
Posted - 2006-07-03 : 08:53:11
|
| imagine th folowing table:id color1 blue2 white3 blue4 blue5 black my desired output is:125I wanna have the first id from an distinct select of the color |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-07-03 : 08:57:24
|
Your question puzzles me. If first means lowest ID for each color, then your desired output is created withSELECT MIN(ID) FROM MyTable GROUP BY Color but every distinct color isSELECT MIN(ID) FROM MyTable GROUP BY Color HAVING COUNT(*) = 1 Peter LarssonHelsingborg, Sweden |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-07-03 : 09:00:53
|
quote: Originally posted by Peso Your question puzzles me.SELECT ID FROM MyTable GROUP BY Color HAVING COUNT(*) = 1Peter LarssonHelsingborg, Sweden
I think that should beSELECT min(ID) FROM @t GROUP BY ColorMadhivananFailing to plan is Planning to fail |
 |
|
|
Stalknecht
Starting Member
22 Posts |
Posted - 2006-07-03 : 16:49:51
|
| Thanks for the solution |
 |
|
|
|
|
|