如何将2个查询的结果按日期排序?
SELECT * FROM table1 WHERE tag='1' SELECT * FROM table2 WHERE tag='3'
table1,table2具有相同的字段: id|article|author|tag|date
id|article|author|tag|date
PS:顺便说一句,标签是 workid
workid
您可以用来UNION ALL从两个表中获取行:
UNION ALL
SELECT id, article, author, tag, date FROM table1 WHERE tag = '1' UNION ALL SELECT id, article, author, tag, date FROM table2 WHERE tag = '3' ORDER BY date
您可能还需要考虑重组数据库,以便代替使用两个表,而只使用一个表和一个字段来区分每一行的类型。然后,查询可以简化为:
SELECT id, article, author, tag, date FROM yourtable WHERE (tag, type) IN (('1','type1'), ('3','type2')) ORDER BY date