2 Votes Vote

Optimize SELECT DISTINCT CONCAT query in MySQL

Posted by topdog 269 days ago Questions| concat distinct distinct concat All

Hello!

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?

Thanks in advanced

1 Answer Bury


Who Voted for this Question



Answers

comment-avatar
topdog
268 days ago
simply run an EXPLAIN on the query to find out what's causing the bottleneck. you don't need a DISTINCT if you're also doing a GROUP BY
Rating: 0   up down

Log in to answer or register here.