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
 General SQL Server Forums
 New to SQL Server Programming
 Select Query ()

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 manner

Work_order Invoice_No Employee_id
10 1 200
11 1 201
12 2 300
13 3 202
14 2 203

But I need to select only single "Invoice_no" for its repeated data's
like..

work_order Invoice_no Employee_id
10 1 200
12 2 300
13 3 202

Any Ideas?
Thanks



Paramu @ 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) t
where t.rn = 1
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-09-16 : 13:23:33
if sql 2000 or earlier use

SELECT t.*
FROM table t
INNER JOIN (SELECT Invoice_no,MIN(Employee_id) AS FirstEmp
FROM table
GROUP BY Invoice_no) t1
ON t1.Invoice_no=t.Invoice_no
AND t1.FirstEmp=t.Employee_id
Go to Top of Page

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

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 result

Rahul Shinde
Go to Top of Page
   

- Advertisement -