Try some thing like this maybe (coded right here might need to fix up)
Code:
Select * From (
Select
DeviceId ,
Value1 ,
Value2 ,
RowNumber() OVER (Partition BY Value2, Value1 Order By DeviceId) AS MyRowNum
From tableName
) x
Where x.MyRowNum > 1
correct, once per device but showing the devices that have that same valuetext2
so there are duplicates in that table but I want to filter it so that I get back records where there are no duplicates but only showing the records where the valuetext2 is related to/used on more than 1 devID
MVP 2007-2010 any chance of a regain?
Professional Software Developer and Infrastructure Engineer.
--mimic your table
declare @myTable table(id int, devid varchar(10), value1 varchar(50), value2 varchar(5))
insert into @myTable(id,devid,value1,value2) Values
(2106064, 'isamirn', '633597819001058916', '2'),
(8080430, 'isamirn', '633597819001058916', '3'),
(8080430, 'isamirn', '633597819001058916', '4'),
(8080430, 'isamirn', '633597819001058916', '5'),
(8080430, 'isamirn', '633597819001058916', '6')
--load temp table with distinct list of ids and value1s
SELECT DISTINCT id, value1
INTO #temp
FROM @myTable
--find duplicates
select *
from #temp
where value1 in (
SELECT value1
from #temp
group by value1
having count(*) > 1)
That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma
Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney
Select DeviceId, Value1,Value2,Count(*) +1 AS Counts FROM (
Select * From (
Select
DeviceId ,
Value1 ,
Value2 ,
RowNumber() OVER (Partition BY Value2, Value1 Order By DeviceId) AS MyRowNum
From tableName
) x
Where x.MyRowNum > 1
)y
Group BY
DeviceId,
Value1,
Value2
SELECT DISTINCT(DeviceId), ValueText1, ValueText2
FROM [DeviceHistory]
WHERE [ValueText2] IN
(
SELECT ValueText2
FROM DeviceHistory
WHERE ValueText1 = 'isamirn' AND ValueText2 <> ''
GROUP BY ValueText2
HAVING COUNT(*) > 1
)
ORDER BY ValueText2
but now to alter it so I am not hardcoding it for isamirn but instead for the unique valuetext1 values instead
Last edited by Techno; Oct 21st, 2011 at 04:30 AM.
MVP 2007-2010 any chance of a regain?
Professional Software Developer and Infrastructure Engineer.