SELECT col1,col2,col3,col4,col5 FROM tablename as m WHERE col3 =(SELECT MAX(col3)FROM tablename WHERE col1 = m.col1)ORDER BY col1
here col3 as date column
Here my table contains around 7000000 records
But it was taking too much time to execute this subquery. And also we have created index for col1 and col3. And we have used dataset and datareader for load the data. But the query was taking more time to execute. And we have tried with limit command also but there is no use.
How to increase the execution performance of the subquery?. I need to fill all the results into dataset or datareader with in seconds (with less time).
We are using C# with MYSQL database.
Any help must be appreciated.
Thanks & Regords Jayaram
Moved byNai-dong Jin - MSFTFriday, November 27, 2009 5:49 AMUnsupported tech. (From:SQL Server Data Access)
Because you are using a aggregate function your subquery, your query may go for scan(table/index). If the no.of records in the table is huge then your response time may have significant impact.
If you have TOP function in MySQL then you can re-write your sub query as "SELECT top 1 col3 FROM tablename WHERE col1=m.col1 order by col3 desc" Regards,Balaji
Please mark as answer if you think this answers your questions