SQL SELECT with condition and unique name
21:49 20 Aug 2012

Say I have the following table. If I want to return ONLY the inactive rows (Active = 0) but disregard a field that has the same FileName. For instance, the query should only return Helper0990329 since it is inactive and has no other filename in another row that is the same. VinnyVincenzo1345090457296 should not be included in the results.

PATH          |         FileName         |   Active                       
C:\Vinny\     VinnyVincenzo1345090457296.mp3    0
C:\Vinny\     VinnyVincenzo1345090457296.mp3    1
C:\Vinny\     VinnyVincenzo1345137702505.mp3    1
C:\Helper\    Helper0990329.mp3                 0

I tried the following but I ended up deactivating (and later deleting) files that I should'nt have:

SELECT 
  
      [Path],
      [FileName]
  
  FROM [Flows].[dbo].[Flows_Flows]
  Where [Active] = '0' AND [Created] > '8/18/2012'
  Group By Path, FileName
  Having count(FileName) = 1
  GO
sql sql-server select