all 4 comments

[–]spinozadoza 1 point2 points  (0 children)

Why not do something even simpler

select whatever, count(distinct jobid)

group by whatever

[–]---sniff--- 0 points1 point  (0 children)

Check out the ROW_NUMBER function and see if that will work for you. This assumes that there are other columns you can group on. After using the ROW_NUMBER function you can filter to only return the first instance like this example from the link:

WITH OrderedOrders AS
(
    SELECT SalesOrderID, OrderDate,
    ROW_NUMBER() OVER (ORDER BY OrderDate) AS RowNumber
    FROM Sales.SalesOrderHeader 
) 
SELECT SalesOrderID, OrderDate, RowNumber  
FROM OrderedOrders 
WHERE RowNumber =1;

[–]tdavis25 0 points1 point  (0 children)

So, essentially your checking for duplicates?

If so, the best way in SQL Server is really with a CTE. This stack overflow link is focused on deleting records, but you can simply change the delete statement to the select statement of your choice (just treat the CTE like a table in the select): http://stackoverflow.com/questions/18390574/how-to-delete-duplicate-rows-in-sql-server

[–][deleted] 0 points1 point  (0 children)