Mysql: Solution for complex query. Multiple limits -


var statements=[]; for(i=1;i<6;i++) {     statements.push(         '(select a.category, a.id,a.country,a.region,a.rajons,a.town town_id,img.t_0, img.main, mt.town, mp.pagasts, mp.pagasts_id, c.link_ link'         +' ads a'                 +' inner join categories c on a.category = c.cat_id'                 +' right join (select t_0,main,ad_id images order main desc) img on a.id = img.ad_id'                 +' left join map_regions mr on a.region = mr.region_id'                 +' left join map_towns mt on a.town = mt.town_id'                 +' left join map_pagasts mp on a.pagasts = mp.pagasts_id'             +' a.region='+i                 +' , a.department !=9'                 +' , (a.town > 0 or a.pagasts > 0)'                 +' , a.charged=1'             +' group a.id'             +' order a.id desc limit 5)'     ); }  statements.join(' union ') 

this main moment in query:

where a.region='+i 

and

limit 5 

is possible other way, without union all?

thanks ;)


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -