Donate

How To Count Duplicate Or Repeating Records From Union All Query In SQL

Here's a query to count number of repeating records based from union all query. Union all query does not remove duplicate records. Here's a sample script:
  select resultsduplicate.url as job_item,  
  count(resultsduplicate.url) as repeat_occurence  
  from  
  (  
    SELECT url FROM mainTable  
     where id = 47 and url like '%testsite.com%' and _active = 1  
    UNION ALL  
    SELECT url FROM detailTable  
     where id = 47 and url like '%testsite.com%' and _active = 1  
  )resultsduplicate   
  group by resultsduplicate.url  
  having (count(resultsduplicate.url) >1);  
Original Source From (Stackoverflow.com)

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.