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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Select question

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--COST
1--200
1--100
3--100
4--200
4--400

What i whish to do is to select the highest of every ID. The result i would like is then:

ID--COST
1--200
3--100
4--400

Can 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 Optimizer
TG
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-27 : 09:13:57
Also, Learn SQL
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

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
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2006-02-27 : 10:45:54
I understand Brain-Freeze all too well
If you want more help, feel free to continue this topic. Please follow the example in this link for defining your problem/question:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -