MySQL - SELECT WHERE field IN (subquery) - Extremely slow why?

前端 未结 10 2165
情书的邮戳
情书的邮戳 2020-11-27 10:06

I\'ve got a couple of duplicates in a database that I want to inspect, so what I did to see which are duplicates, I did this:

SELECT relevant_field
FROM some         


        
10条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 10:18

    I find this to be the most efficient for finding if a value exists, logic can easily be inverted to find if a value doesn't exist (ie IS NULL);

    SELECT * FROM primary_table st1
    LEFT JOIN comparision_table st2 ON (st1.relevant_field = st2.relevant_field)
    WHERE st2.primaryKey IS NOT NULL
    

    *Replace relevant_field with the name of the value that you want to check exists in your table

    *Replace primaryKey with the name of the primary key column on the comparison table.

提交回复
热议问题