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 |
|
peronn
Starting Member
2 Posts |
Posted - 2006-02-26 : 15:49:12
|
| Hi,I have a question reagarding an SELECT statement.What i have is a table that looks like below.ID--COST1--2001--1003--1004--2004--400What i whish to do is to select the highest of every ID. The result i would like is then:ID--COST1--2003--1004--400Can anybody help me with this? I have tried Distinct but i guees it doesnt work since i need both values.Please help. Any help is appriciated.P |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2006-02-26 : 18:26:55
|
| select [ID], max(Cost) as MaxCost from myTable group by [ID]Be One with the OptimizerTG |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-02-27 : 09:13:57
|
| Also, Learn SQLhttp://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp MadhivananFailing to plan is Planning to fail |
 |
|
|
peronn
Starting Member
2 Posts |
Posted - 2006-02-27 : 09:23:18
|
| Hi, thanks for your replies.The statement worked at first but now as the table has grown and become more complex containing bit-columns and so on i can't get it to work. (Not my DB originaly just taking over a project)And I'have studied quite a lot of sql during my major year at uni but one tends to forget if you don't work with it. And with this perticular statement my brain froze :)P |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
|
|
|
|
|