Home >Backend Development >PHP Tutorial > 求mysql一条语句,该如何处理

求mysql一条语句,该如何处理

WBOY
WBOYOriginal
2016-06-13 13:35:28818browse

求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
------解决方案--------------------
按情况分组 每组取一条记录

SQL code
SELECT * FROM (SELECT * FROM `table` ORDER BY `condition` DESC) t GROUP BY `condition`; <div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn