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 |
|
david_reinjal
Starting Member
36 Posts |
Posted - 2006-12-18 : 06:23:49
|
| hi guys,I have 4 columns and 3 rows. Columns are Name, Age, Gender and Weight. I have values entered for each column. I need to pick the highest value of weight if Name, Age, Gender are same and put that into new table. how can i do that? |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-12-18 : 06:26:40
|
| --insert into ...select top 1 * from <yourtablenamehere> order by weight descPeter LarssonHelsingborg, Sweden |
 |
|
|
david_reinjal
Starting Member
36 Posts |
Posted - 2006-12-18 : 06:36:11
|
| this will sort in descending order. but i need to choose only that row which is having highest value for weight and insert in new table. |
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2006-12-18 : 06:58:24
|
| did you even try it? You do know that 'SELECT TOP 1' will give you one row, right?You do know that descending order will put the highest value first, right?[Signature]For fast help, follow this link:http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspxLearn SQLhttp://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-12-18 : 07:23:01
|
Thank you Don AtWork! Now I think hos professor told him to write this--INSERT ...SELECT Name, Age, Gender, MAX(Weight)FROM <YourTableNameHere>GROUP BY Name, Age, Gender Peter LarssonHelsingborg, Sweden |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-12-18 : 09:26:05
|
quote: Originally posted by david_reinjal hi guys,I have 4 columns and 3 rows. Columns are Name, Age, Gender and Weight. I have values entered for each column. I need to pick the highest value of weight if Name, Age, Gender are same and put that into new table. how can i do that?
1 It is just use of MAX function2 You dont need to have seperate table to have those data. It is just display and use only SELECT statement3 Learn SQLhttp://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.aspMadhivananFailing to plan is Planning to fail |
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2006-12-18 : 10:10:13
|
I didn't want you hogging all the evil Peter [Signature]For fast help, follow this link:http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspxLearn SQLhttp://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
|
|
|
|
|