求mysql一条语句
按id降序查询几种情况的各一条记录,用一条语句能否实现?
[解决办法]
union 可不可以的,没用过
[解决办法]
对
(select * from a order by id desc limit 0,1) union all (select * from b order by id desc order by id desc limit 0,1)
[解决办法]
可以啊,用UNION ALL
[解决办法]
按情况分组 每组取一条记录
SELECT * FROM (SELECT * FROM `table` ORDER BY `condition` DESC) t GROUP BY `condition`;