MySql query taking too long time to give result
Select pty_code from sis.tblBf a where a.BFno
not in (select b.BNo from sislatest.tbltransaction b)
note: i am comparing two different database and getting the difference.
Select A.pty_code from DataBase1.TableName A
where A.BFno NOT IN (SELECT B.BNo From DataBase2.TableName B)
Perhaps an indexing issue? This is where the mysql explain syntax comes in hand:
http://dev.mysql.com/doc/refman/5.0/en/using-explain.html
Other things that may help would be to 'optimize table', or even 'analyze table' to check for inconsistency.
Using a subselect, especially with a "not in" clause is going to be slow. I'd recommend rewriting to a left outer join with an "is null" in the where clause.
SELECT a.pty_code from sis.tblBf a LEFT JOIN sislatest.tbltransaction b on b.BNo = a.BFno WHERE b.BNo IS NULL
I think that would work but without the database to test against, I'm writing it blind.
If that's still slow, I'd take a look and make sure there are indices on b.BNo and A.BFNo.