Results 1 to 2 of 2
  1. #1
    swap5032 is offline new member
    Join Date
    Sep 2010
    Posts
    2

    Default 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.

  2. #2
    swap5032 is offline new member
    Join Date
    Sep 2010
    Posts
    2

    Default 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)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Content Relevant URLs by vBSEO 3.6.0