GET 24/7 LIVE HELP NOW

Announcement

Announcement Module
Collapse
No announcement yet.

Need Help for Mysql-Query optimization

Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need Help for Mysql-Query optimization

    I have run this query make a more time please any body optimize this query as blew

    $sql="SELECT f.feeder_code, f.subdivision_code FROM `feeder` f, sentout s
    where ( f.start_date <= '2008-07-01' and f.end_date >= '2008-07-01' and
    (s.month = 7 and s.year = 8 )) and f.feeder_code = s.feeder_code
    UNION
    SELECT feeder_code, subdivision_code FROM ht WHERE ht.month = 7 and
    ht.year = 8 and concat( feeder_code, subdivision_code ) NOT IN
    (SELECT concat( f.feeder_code, f.subdivision_code )
    FROM `feeder` f, sentout s where (f.start_date <= '2008-07-01' and f.end_date >='2008-07-01' and (s.month = 7 and s.year = 8)) and f.feeder_code = s.feeder_code)
    UNION
    SELECT feeder_code, subdivision_code FROM lt WHERE lt.month = 7
    and lt.year = 8 and concat( feeder_code, subdivision_code ) NOT IN
    ( SELECT concat( f.feeder_code, f.subdivision_code ) FROM feeder f, sentout s
    where (f.start_date<= '2008-07-01' and f.end_date >= '2008-07-01' and
    (s.month = 7 and s.year = 8)) and f.feeder_code = s.feeder_code
    ) AND concat( feeder_code, subdivision_code ) NOT IN ( SELECT concat( feeder_Code, subdivision_code )
    FROM ht WHERE ht.month = 7 and ht.year = 8)
    ORDER BY feeder_code, subdivision_code";

    solved this problem because this take a more time

  • #2
    Don't use NOT IN() subqueries. Use an exclusion join instead.

    Comment

    Working...
    X