我知道union查询必须有相同数量的列。我试图从表comments得到结果,并从表strings得到结果,该结果有多个连接。我如何正确?我还没有测试,因为我知道我会得到一个列数不同的错误。这是我试图结合的两个查询。mysql union不同列数
查询1(串)
SELECT sub.actionid as usersub,
ftable.`last-time` as lastvisited, updatetable.recent as mostrecent, parent.* FROM `strings` as parent
LEFT JOIN subscribe sub on sub.actionid=parent.id AND sub.userid=:userid
JOIN followers ftable on ((ftable.sid=parent.sid AND ftable.page='1') OR
(ftable.sid=parent.sid AND ftable.position=parent.position AND ftable.page='0')
OR (ftable.profile=parent.starter AND parent.guideline='1')) AND ftable.userid=:userid
JOIN `update-recent` updatetable on
((updatetable.sid=parent.sid AND updatetable.position=parent.position AND updatetable.pageid='0')
OR (updatetable.profile=parent.starter) OR (updatetable.pageid=parent.pageid AND parent.pageid!=0))
WHERE ftable.userid=:userid AND parent.deleted='0' GROUP BY parent.id
查询2(评论)
SELECT * FROM comments WHERE viewed='0' AND (`starter-id`=:userid OR respondid=:userid)
我想通过时间戳列posted(最近)ORDER BY posted DESC
订购的结果我如何结合这些查询?
+0
查询中没有聚合函数,那么GROUP BY的含义是什么? –
2013-04-07 20:08:45
+0
[联合两个不同列数的表]的可能重复(http://stackoverflow.com/questions/2309943/unioning-two-tables-with-different-number-of-columns) –
2014-04-27 23:23:40