14
Views
1
Comments
Solved
Do you have the suggestion to optimise this sql syntax to check the duplication data?
Question
Application Type
Reactive

Do you have the suggestion to optimise this sql syntax to check the duplication data?


(CASE WHEN ((SELECT COUNT (*)

    FROM {Table A}

    INNER JOIN ...

    WHERE ...

    ) >= 2) THEN (True) ELSE (False) END)

2019-01-07 16-04-16
Siya
 
MVP
Solution

One optimisation I could think of is ’exists’ instead of count.

SELECT CASE 

         WHEN EXISTS (SELECT 1

                      FROM {Table A} A

                      INNER JOIN ...

                      WHERE ...

                      GROUP BY {columns to determine duplication}

                      HAVING COUNT(*) > 1) 

         THEN True 

         ELSE False 

       END AS HasDuplicate


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.