sql >> Databasteknik >  >> RDS >> Sqlserver

Hitta dubbletter i en kolumn genom att välja var i SQL Server 2008

SELECT Id, Terms, Track, Active
FROM QueryData
WHERE Terms IN (
                SELECT Terms 
                FROM QueryData
                WHERE Track = 'Y' and Active = 'Y' 
                GROUP BY Terms
                HAVING COUNT(*) > 1
                )

Demo på SQLFiddle

Data:

ID      Terms     Track    Active
100     paper     Y        Y
200     paper     Y        Y
100     juice     Y        Y
400     orange    N        N
1000    apple     Y        N

Resultat:

Id      Terms     Track    Active
100     paper     Y        Y
200     paper     Y        Y


  1. konvertera bild i minnet till en blob

  2. Postgresql gör null till noll

  3. CONTAINS fungerar inte med Oracle Text

  4. hibernate.jdbc.fetch_size eller @QueryHints(@javax.persistence.QueryHint(name=org.hibernate.fetchSize, value=10)) fungerar inte