两个结果UNION不行? select * from (select * from 表名 where 条件 order by 排序字段 desc limit 10) union select * from (select * from 表名 where 条件 order by 排序字段 desc limit 10)
select * from A inner Join B on A.id=B.id where 条件 order by newstime desc limit 10
估计是想这样。猜的。select * from ( select * from 表名1 where 条件 union all select * from 表名2 where 条件 ) order by 排序字段 desc limit 10
4楼代码:SELECT * FROM ( SELECT * FROM phome_ecms_info UNION ALL SELECT * FROM phome_emcs_house ) ORDER BY newstime DESC LIMIT 10 MySQL 返回: #1248 - Every derived table must have its own alias 实在是不懂SQL, 我加上as,错误还是一样。 表的结构看这里的 4楼 http://topic.csdn.net/u/20090322/15/160a3e85-d0f3-4f80-a9f7-106e2c6417c0.html被这个东西弄得头都大了
SELECT * FROM ( SELECT A.title AS A_title,A.area as.A_area,A.newstime AS A_newstime FROM phome_ecms_info A UNION ALL SELECT B.title AS B_title,B.area as.B_area,B.newstime AS B_newstime FROM phome_emcs_house B ) ORDER BY A_newstime DESC,B_newstime DESC LIMIT 10
select * from
(select * from 表名 where 条件 order by 排序字段 desc limit 10)
union
select * from
(select * from 表名 where 条件 order by 排序字段 desc limit 10)
(
select * from 表名1 where 条件
union all
select * from 表名2 where 条件
)
order by 排序字段 desc limit 10
这样是不行的!!!UNION逻辑操作不能与ORDER BY操作同时出现在一个语句中的。
参考四楼的代码,是可以的!!变通一下啊。
FROM (
SELECT *
FROM phome_ecms_info
UNION ALL SELECT *
FROM phome_emcs_house
)
ORDER BY newstime DESC
LIMIT 10 MySQL 返回: #1248 - Every derived table must have its own alias 实在是不懂SQL, 我加上as,错误还是一样。
表的结构看这里的 4楼 http://topic.csdn.net/u/20090322/15/160a3e85-d0f3-4f80-a9f7-106e2c6417c0.html被这个东西弄得头都大了
FROM (
SELECT A.title AS A_title,A.area as.A_area,A.newstime AS A_newstime
FROM phome_ecms_info A
UNION ALL
SELECT B.title AS B_title,B.area as.B_area,B.newstime AS B_newstime
FROM phome_emcs_house B
)
ORDER BY A_newstime DESC,B_newstime DESC
LIMIT 10