$query = "SELECT arc.*,tp.typedir,tp.typename,tp.isdefault,tp.defaultname, tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath $addField FROM {$this->maintable} arc LEFT JOIN #@__arctype tp ON arc.typeid=tp.id $addJoin WHERE arc.arcrank > -1 AND channel>-1 AND arc.channel = '1' AND CONCAT(arc.title) REGEXP '关键词一' AND CONCAT(arc.title) REGEXP '关键词二‘ ORDER BY arc.pubdate desc LIM
IT $limitstart,".$this->PageSize; $this->dsql->SetQuery($query);
上面的在PHP文件里一段查询,语句查询出来后是先查询了所有结果,然后把所有结果按照发布时间降序排列。
问题:请问怎么改成,先匹配关键词一的查询结果(按照降序排列),然后再匹配关键词二(也是按照降序排列)的查询结果,然后把2个结果合并在一起呢??
两个查询union 起来就隐陪好:
SELECT arc.*,tp.typedir,tp.typename,tp.isdefault,tp.defaultname, tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath $addField FROM {$this->maintable} arc LEFT JOIN #@__arctype tp ON arc.typeid=tp.id $addJoin WHERE arc.arcrank > -1 AND channel>-1 AND arc.channel = '1' AND CONCAT(arc.title) REGEXP '关键词一' ORDER BY arc.pubdate desc
union
SELECT arc.*,tp.typedir,tp.typename,tp.isdefault,tp.defaultname,
tp.namerule,tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath
$addField FROM {$this->行缺maintable} arc LEFT JOIN
#@__arctype tp ON arc.typeid=tp.id $addJoin WHERE
arc.arcrank > -1 AND channel>-1 AND arc.channel = '1'灶带蠢 AND
CONCAT(arc.title) REGEXP '关键词二' ORDER BY arc.pubdate desc
时间降序的话用order by time asc或desc