Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2002
    Posts
    84

    Question Unanswered: Slow performance of SQL statement

    Dear All,

    I have the following SQL statement in MySQL that needs to join some tables. It seems that it is not quite efficient, which caused the program to be slow. Is there anyway to fine tune it? Thanks!

    ----------------------------------------------------------------------
    SELECT REPORT_DATE, MAINT_COUNTRY_CODE, REPORT_TYPE_NAME, REPORT_TITLE, REPORT_DESC, REPORT_RATING, REPORT_ID, MAINT_SECTOR_NAME FROM TBL_REPORT JOIN TBL_MAINT_COUNTRY ON TBL_REPORT.REPORT_COUNTRY = TBL_MAINT_COUNTRY.MAINT_COUNTRY_ID JOIN TBL_REPORT_TYPE ON TBL_REPORT.REPORT_REPORT_TYPE = TBL_REPORT_TYPE.REPORT_TYPE_ID INNER JOIN TBL_MAINT_SECTOR ON MAINT_SECTOR_ID=REPORT_SECTOR_ID WHERE (REPORT_REPORT_TYPE = '8' OR REPORT_REPORT_TYPE='6') AND RPT_SECTOR_ID = '1' AND REPORT_STATUS = 'A' ORDER BY REPORT_DATE DESC"

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    yes, there is an easy way to optimize this query -- make sure you have declared an index on each join column (note: primary key counts as an index)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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