mysql - sql how to use this syntax more light weight? -


hello i'm getting message:

[the select examine more max_join_size rows; check , use set sql_big_selects=1 or set max_join_size=# if select okay] 

on syntax:

    select concat(v2.meta_value, ' ', v3.meta_value) name,  a.usr, a.vagtdato, b.timeloen, c.provision, d.kursus, e.trappetur, f.sygedag $main_table left join (select usr, count(vagt_type) timeloen $main_table  vagt_type = 'timeloen' , vagtdato between date('$start') , date('$end') group usr ) b on b.usr=a.usr  left join (select usr, count(vagt_type) provision $main_table  vagt_type = 'provision' , vagtdato between date('$start') , date('$end') group usr ) c on c.usr=a.usr  left join (select usr, count(vagt_type) kursus $main_table  vagt_type = 'kursus' , vagtdato between date('$start') , date('$end') group usr ) d on d.usr=a.usr  left join (select usr, count(vagt_type) trappetur $main_table  vagt_type = 'trappetur' , vagtdato between date('$start') , date('$end') group usr ) e on e.usr=a.usr  left join (select usr, count(vagt_type) sygedag $main_table  vagt_type = 'sygedag' , vagtdato between date('$start') , date('$end') group usr ) f on f.usr=a.usr  left join lausten_usermeta v2 on a.usr=v2.user_id , v2.meta_key = 'first_name' left join lausten_usermeta v3 on a.usr=v3.user_id , v3.meta_key = 'last_name'  a.vagtdato between date('$start') , date('$end') group a.usr order $orderby $order limit %d offset %d 

so know can set higher limit i'd aviod that!

is there way make syntax more light weight?

you can use conditional aggregation subqueries:

left join (select usr,                   sum(vagt_type = 'timeloen') timeloen,                   sum(vagt_type = 'provision') provision,                   . . .            $main_table             vagtdato between date('$start') , date('$end')            group usr           ) b           on b.usr = a.usr 

this replace subqueries one.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -