2 different small query vs 1 query with subquery

前端 未结 4 1239
无人及你
无人及你 2021-01-04 05:04

I have table like this

name       | personal_number 
-----------------------------------------
Jon        | 222
Alex       | 555
Jon        | 222
Jimmy               


        
4条回答
  •  有刺的猬
    2021-01-04 05:32

    This should be quicker:

    SELECT  name  FROM mytable join (
            SELECT  personal_number  FROM mytable  GROUP BY personal_number
            HAVING COUNT(*) > 1
    )a using (personel_number)
    

    Edit: If this is faster than variant 1, then it means at variant 1 mysql reproduces the inner table for each record again and again.

提交回复
热议问题