Home > Database > Mysql Tutorial > body text

MySQL中查询后记录集的排序问题

WBOY
Release: 2016-06-07 16:55:17
Original
1015 people have browsed it

在MySQL上一般的查询要么是按一个字段的升序,要么按降序进行排序,如果实现根据条件里值的左右顺序来显示记录呢,如 where id i

在MySQL上一般的查询要么是按一个字段的升序,要么按降序进行排序,如果实现根据条件里值的左右顺序来显示记录呢,如 where id in (3,1,5,2)此类的,查询出来的记录从上到下也是(3,1,5,2)这类的顺序了,可以用以下语句来实现:

SELECT * FROM documents WHERE id IN (3,5,7) ORDER BY FIELD(id,3,5,7)

linux

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template