1

I'm running this query:

SELECT DISTINCT CONCAT(ALFA_CLAVE, FECHA_NACI) FROM listado GROUP BY ALFA_CLAVE HAVING count(CONCAT(ALFA_CLAVE, FECHA_NACI)) > 1

Is there any way to optimize it? Queries are taking 2-3 hours on a table with 850,000 rows.

Adding an index to ALFA_CLAVE and FECHA_NACI would work?

1 Answer 1

1

mysql don't have functional/expression index capability, it cannot put an index on a function/expression.

try it this way, i.e. concat them later:

select concat(x.alfa_clave, x.fecha_naci) 
from
(
    SELECT ALFA_CLAVE, FECHA_NACI 
    FROM listado 
    GROUP ALFA_CLAVE, FECHA_NACI 
    HAVING COUNT(*) > 1
) as x 
Sign up to request clarification or add additional context in comments.

1 Comment

If you put the sub-select in a temporary table first, you can shave off some seconds: create temporary table temp1 SELECT ALFA_CLAVE, FECHA_NACI FROM listado GROUP ALFA_CLAVE, FECHA_NACI HAVING COUNT(*) > 1; select concat(alfa_clave, fecha_naci) from temp1;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.