Hola, tengo una tabla con más de 30.000 registros y me han dicho que los Select Distinct son muy lentos a la hora de arrojar resultados. Estoy tratando de convertir un Select Distinct en un Select anidado para mejorar los tiempos de respuesta, pero no doy con ello.
El código original es este:
"SELECT DISTINCT " & _
"Disc_Topics.TopicId, " & _
"Disc_Topics.ForumId, " & _
"Disc_Topics.user_id, " & _
"Disc_Topics.last_user_id, " & _
"Disc_Topics.Icon, " & _
"Disc_Topics.Subject, " & _
"Users.user_name, " & _
"Users2.user_name as lastuser_name, " & _
"Disc_Topics.DateAdded, " & _
"Disc_Topics.Replies, " & _
"Disc_Topics.Views, " & _
"Disc_Topics.Locked, " & _
"Disc_Topics.Sticky, " & _
"Disc_Topics.DateLast FROM (((Disc_Topics LEFT JOIN Users ON Disc_Topics.user_id = Users.user_id) LEFT JOIN Users as Users2 ON Disc_Topics.last_user_id = Users2.user_id) LEFT JOIN Disc_Replies ON Disc_Replies.topicid = Disc_Topics.topicid)" & _
"WHERE Disc_Topics.visible =1 " & _
"ORDER BY Sticky DESC, DateLast DESC"
Y quiero convertirlo en algo parecido a esto:
"SELECT Disc_Topics.TopicId, Disc_Topics.ForumId, Disc_Topics.user_id, Disc_Topics.last_user_id, Disc_Topics.Icon, Disc_Topics.Subject, Disc_Topics.DateAdded, Disc_Topics.Replies, Disc_Topics.Views, Disc_Topics.Locked, Disc_Topics.Sticky, Disc_Topics.DateLast FROM Disc_Topics WHERE EXISTS ( Select user_name FROM Users WHERE Disc_Topics.user_id = Users.user_id) AND (Select user_name as lastuser_name FROM Users as Users2 WHERE Disc_Topics.last_user_id = Users2.user_id) AND (Select * FROM Disc_Replies WHERE Disc_Replies.topicid = Disc_Topics.topicid) AND Disc_Topics.visible =1 ORDER BY Sticky DESC, DateLast DESC"
Pero nada, no consigo que me funcione. Gracias a quien me pueda ayudar.!!