Home > Database > Mysql Tutorial > body text

mysql in根据查询id排序_MySQL

WBOY
Release: 2016-06-01 13:35:58
Original
1256 people have browsed it

bitsCN.com


mysql in根据查询id排序

 

mysql in根据查询时,返回结果是自行排序的,如果要按照我们查询的ID进行排序,
要用到order by field,下面用几个例子来说明一下mysql in查询排序

 

例子: www.bitsCN.com  

 

SQL:select * from table where id IN (3,6,9,1,2,5,8,7);

 

这样的情况取出来后,其实,id还是按1,2,3,4,5,6,7,8,9,排序的,但如果我们真要按IN里
面的顺序排序怎么办?我们可以用order by field

 

SQL: select * from table where id IN (3,6,9,1,2,5,8,7) order by field(id,3,6,9,1,2,5,8,7);

 

查询出来的结果就是按自定义的ID进行排序了.
 

bitsCN.com
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