| Author |
Topic |
|
kalyan.cse05
Yak Posting Veteran
74 Posts |
Posted - 2010-12-28 : 05:12:30
|
| I want to select a randam value (for a specific field).for example:100003 Tedlie, Beth 8-Complete 2009-06-30 17:00:00.000100003 Tedlie, Beth A 8-Complete 2009-06-30 17:00:00.000100007 Sankaranarayanan, Vaidy; Shandon 8-Complete 2009-09-16 17:00:00.000100007 Sankaranarayanan, Vaidyanath 8-Complete 2009-09-16 17:00:00.000from here i want only 1 record each for 100003 and 100007kalyan Ashis Dey |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-12-28 : 05:24:07
|
| What do you mean randomly?What should be the o/p for the data you posted?PBUH |
 |
|
|
kalyan.cse05
Yak Posting Veteran
74 Posts |
Posted - 2010-12-28 : 05:29:26
|
| O/p will be 100003 Tedlie, Beth 8-Complete 2009-06-30 17:00:00.000100007 Sankaranarayanan, Vaidy; Shandon 8-Complete 2009-09-16 17:00:00.000kalyan Ashis Dey |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-12-28 : 05:31:52
|
quote: Originally posted by kalyan.cse05 O/p will be 100003 Tedlie, Beth 8-Complete 2009-06-30 17:00:00.000100007 Sankaranarayanan, Vaidy; Shandon 8-Complete 2009-09-16 17:00:00.000kalyan Ashis Dey
On what basis ?PBUH |
 |
|
|
kalyan.cse05
Yak Posting Veteran
74 Posts |
Posted - 2010-12-28 : 05:35:45
|
| i need the first row from each trackingnumbertrackingnumber,managername,status,finishdate 100003 Tedlie, Beth 8-Complete 2009-06-30 17:00:00.000100007 Sankaranarayanan, Vaidy; Shandon 8-Complete 2009-09-16 17:00:00.000kalyan Ashis Dey |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-12-28 : 05:41:30
|
quote: Originally posted by kalyan.cse05 i need the first row from each trackingnumbertrackingnumber,managername,status,finishdate 100003 Tedlie, Beth 8-Complete 2009-06-30 17:00:00.000100007 Sankaranarayanan, Vaidy; Shandon 8-Complete 2009-09-16 17:00:00.000kalyan Ashis Dey
Then how do you define your first row ?Visually anyone can say 100003 Tedlie, Beth 8-Complete 2009-06-30 17:00:00.000is the first row but we need to make SQL understand that it is indeed the first row.PBUH |
 |
|
|
kalyan.cse05
Yak Posting Veteran
74 Posts |
Posted - 2010-12-28 : 05:44:28
|
| i mean to say i need any of the row not first or not second ,just i need no duplicate row comingkalyan Ashis Dey |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-12-28 : 05:46:20
|
| Then is it ok if on the next execution 100003 Tedlie, Beth A 8-Complete 2009-06-30 17:00:00.000 is shown in the resultset ?PBUH |
 |
|
|
kalyan.cse05
Yak Posting Veteran
74 Posts |
Posted - 2010-12-28 : 05:48:40
|
| yes:)kalyan Ashis Dey |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-12-28 : 05:57:28
|
| select T.* from yourtable t1cross apply(select top 1 * from yourtable t2 where t1.id=t2.id)TPBUH |
 |
|
|
matty
Posting Yak Master
161 Posts |
Posted - 2010-12-28 : 06:21:24
|
| [code]SELECT trackingnumber,managername,status,finishdate FROM( SELECT *,ROW_NUMBER() OVER(PARTITION BY trackingnumber ORDER BY newid()) AS rownum FROM MyTable)tWHERE t.rownum = 1[/code] |
 |
|
|
kalyan.cse05
Yak Posting Veteran
74 Posts |
Posted - 2010-12-28 : 06:39:15
|
| Thanks a lot.It works perfectlykalyan Ashis Dey |
 |
|
|
|