Thread: MySql query optimization
-
20-09-2010, 04:08 #1
new member
- Join Date
- Sep 2010
- Posts
- 2
MySql query optimization
Hello,
I would like to share a MySql query optimization scenario with you all.
As one of our clients had a requirement of showing client
follow ups in client wise way ( SQL : GROUP BY client_id clause ) with client "Name" (MySql "client_data" table ), and client "status", "comments" ( from "client_followup" table ). I had to join two tables ( "client_data" and "client_followup" ) and also wanted to show last client_followup "status" and "comment" posted.
As SQL basics if I use SQL "ORDER BY" clause after "GROUP BY" statement it affects the results not the groups of clients.
My requirement was to ORDER group of clients by "sdate" (from client_followup table).
One work around I found was to have a join of client_data table and table from nested query (which will order client_followup by "sdate" column).
But unfortunately It did not work because nested queries take more time to execute.
In my case it was more than "6 seconds" (too expensive).
My problem was that mysql table by default get sorted on primary key in ASCENDING order.
I fired following query
"ALTER TABLE `client_followup` ORDER BY `sdate` DESC"
This forces mysql table to be by default sorted on "sdate" column and instead of nested query solution I have fired simple join and my query got optimized (0.0291 seconds)
I thought this might be useful to everyone working on such queries.Last edited by swap5032; 20-09-2010 at 10:52.
-
22-09-2010, 10:07 #2
new member
- Join Date
- Sep 2010
- Posts
- 2
Any ideas related this are welcome
Hello,
Any ideas regarding this issue are welcome.
I strongly encourage you all to suggest any new solution.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)


LinkBack URL
About LinkBacks



Reply With Quote


It appears not. What a huge, pointless, unecessary, infuriating waste of time.
Domain down can't contact Eukhost