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 |
|
gagani
Posting Yak Master
112 Posts |
Posted - 2011-11-15 : 09:48:40
|
| from the table,value date100 21/10/2011 139 22/10/2011 140 23/10/2011 I want the value for the minimum date, that is output should be 100Could anyone please write a query |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-15 : 09:54:16
|
| [code]SELECT TOP 1 valueFROM tableORDER BY date ASC[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2011-11-15 : 09:57:43
|
| If you have mutiple record against single (minimum) date thenSELECT * FROM tableWHERE [date] IN (SELECT MIN([date]) FROM table)--------------------------http://connectsql.com/ |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-15 : 09:59:44
|
even this would doSELECT TOP 1 WITH TIESvalueFROM tableORDER BY date ASC ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2011-11-15 : 10:05:50
|
| Visakh, You are brillient.--------------------------http://connectsql.com/ |
 |
|
|
gagani
Posting Yak Master
112 Posts |
Posted - 2011-11-15 : 10:17:50
|
| sorry, i didnt put it right id value status datecolumn101 100 1 21/01/2011101 110 2 22/01/2011101 120 1 23/01/2011102 300 1 25/01/2011102 400 2 26/01/2011for the given table, i need the value when status = 1 and within that status i want to choose the value for minimum dateoutput should be101 100 102 300 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-15 : 10:21:13
|
| [code]SELECT t.*FROM table tINNER JOIN (SELECT id,min(datecolumn) as datevalue WHERE status = 1 GROUP BY id )t1ON t1.id = t.idAND t1.datevalue = t.datecolumnWHERE t.status =1[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-11-16 : 05:02:11
|
quote: Originally posted by visakh16
SELECT t.*FROM table tINNER JOIN (SELECT id,min(datecolumn) as datevalue from table WHERE status = 1 GROUP BY id )t1ON t1.id = t.idAND t1.datevalue = t.datecolumnWHERE t.status =1 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|