mysql - Query takes too long to fetch data -


i aware of slow query log isnt queries exceed maximum execution time? question different (i think).

i running below query , me doesnt seem should present problem. when run it, "running" time on 20 seconds , sits there "fetching" ages! point have stop due db performance issues.

can explain going wrong here. coding newbie please gentle.

select  t1.oid, (select          date_format(t2.date,                     '%d/%m/%y') 'avf date'             t2             t1.oid = t2.fk_oid             , t2.type = '-25'             , year(t2.date) between 2005 , 2014     order t2.date asc     limit 1) 'avf date', t2.site  t1 left join t2 on t1.oid=t2.fk_oid 

update - ok need follows. have patient database , these patients have procedures recorded on database. trying return patient oid (t1.oid) along first procedure had (if between 2005 , 2014) , had (t2.date , t2.site respectively), if procedure of particular type (t2.type = '-25')

so basically. patients had avf between 2005 , 2014 along "site" of avf (which in case left arm/right arm etc.)

i hope makes bit clearer.

thanks in advance.

mikey

i think can use join without subquery in select, have try:

select t1.oid, date_format(t2.date,'%d/%m/%y'),t2.site table1 t1 left join table2 t2 on t1.oid = t2.fk_oid     t2.type = '-25'     , year(t2.date) between 2005 , 2014 order t2.date asc limit 1; 

ps: haven't tested code.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -