# Need Help for Mysql-Query optimization

**URL:** <https://forums.percona.com/t/need-help-for-mysql-query-optimization/990>\
**Category:** Other MySQL® Questions\
**Created:** [November 7, 2008, 6:56am UTC](https://forums.percona.com/t/need-help-for-mysql-query-optimization/990 "2008-11-07T06:56:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yashvant](https://avatars.discourse-cdn.com/v4/letter/y/c77e96/32.png) [@yashvant](https://forums.percona.com/u/yashvant)\
**Post date:** [November 7, 2008, 6:56am UTC](https://forums.percona.com/t/need-help-for-mysql-query-optimization/990/1 "2008-11-07T06:56:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![xaprb](https://avatars.discourse-cdn.com/v4/letter/x/49beb7/32.png) [@xaprb](https://forums.percona.com/u/xaprb)\
**Post date:** [January 23, 2010, 12:11pm UTC](https://forums.percona.com/t/need-help-for-mysql-query-optimization/990/2 "2010-01-23T12:11:29Z")

</div>

Don’t use NOT IN() subqueries. Use an exclusion join instead.
