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 |
|
paramu
Posting Yak Master
151 Posts |
Posted - 2009-09-15 : 09:41:56
|
| I have a table called "Invoice_Curs" like the following mannerWork_order Invoice_No Employee_id10 1 20011 1 20112 2 30013 3 20214 2 203But I need to select only single "Invoice_no" for its repeated data'slike..work_order Invoice_no Employee_id10 1 20012 2 30013 3 202Any Ideas?ThanksParamu @ PARANTHAMAN |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-09-15 : 09:46:56
|
try this..select * from(select row_number() over(partition by invoice_no order by employee_id) as rn,* from Invoice_Curs) twhere t.rn = 1 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-09-16 : 13:23:33
|
if sql 2000 or earlier useSELECT t.*FROM table tINNER JOIN (SELECT Invoice_no,MIN(Employee_id) AS FirstEmp FROM table GROUP BY Invoice_no) t1ON t1.Invoice_no=t.Invoice_noAND t1.FirstEmp=t.Employee_id |
 |
|
|
nirene
Yak Posting Veteran
98 Posts |
Posted - 2009-09-17 : 01:23:20
|
| Select Invoice_no,Min(Work_order) as Work_order,Min(Employee_id) as Employee_id from Invoice_Curs Group By Invoice_No |
 |
|
|
ra.shinde
Posting Yak Master
103 Posts |
Posted - 2009-09-17 : 03:39:18
|
quote: Originally posted by nirene Select Invoice_no,Min(Work_order) as Work_order,Min(Employee_id) as Employee_id from Invoice_Curs Group By Invoice_No
This will certanly return wrong resultRahul Shinde |
 |
|
|
|
|
|