SELECT * FROM (SELECT id,ach,'X' AS counter,'A' AS class,date FROM tablename1 as t1 WHERE 1 UNION SELECT id,ach,counter,'B' AS class,date FROM tablename2 as t2 WHERE 1) AS tall order by date asc
建议增加条件,且为索引字段.其次查的数据量不能太大,不然临时表会占据较多的内存空间.宁可牺牲硬盘空间,也不要无谓的牺牲内存空间.
从长远角度来说,建议整合2个表.
SELECTa.name,b.name
FROM
blog_index
a
INNER
JOIN
news_index
b
ON
a.xx=b.xx
xx是用来连接a和b的字段名
如果连接两个表的字段名是一样的可以简写为
SELECT
a.name,b.name
FROM
blog_index
a
INNER
JOIN
news_index
b
USING(xx)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)