var statements=[];
for(i=1;i<6;i++)
{
statements.push(
'(SELECT a.category, a.id,a.country,a.region,a.rajons,a.town AS town_id,img.t_0, img.main, mt.town, mp.pagasts, mp.pagasts_id, c.link_ AS link'
+' FROM ads a'
+' INNER JOIN categories c ON a.category = c.cat_id'
+' RIGHT JOIN (SELECT t_0,main,ad_id FROM images ORDER BY main DESC) AS 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'
+' WHERE a.region='+i
+' AND a.department !=9'
+' AND (a.town > 0 OR a.pagasts > 0)'
+' AND a.charged=1'
+' GROUP BY a.id'
+' ORDER BY a.id DESC LIMIT 5)'
);
}
statements.join(' UNION ALL ')
这是查询中的主要时刻:
WHERE a.region='+i
和
LIMIT 5
是否有可能以其他方式进行,没有UNION ALL
?
谢谢;)