按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
------解决方案--------------------
按情况分组 每组取一条记录
sql codeselect * from (select * from `table` order by `condition` desc) t group by `condition`;
