mysql按照特定顺序搜索数据

WBOY
Release: 2016-06-06 20:08:11
Original
947 people have browsed it

想知道有没有一个方法能够让mysql按照指定的顺序返回数据。
例如我想搜索id=1、2、3的数据。
无论是写成where id in(1,2,3)还是where id in (1,3,2),mysql都是按照1、2、3的顺序返回结果,能不能指定mysql按照1、3、2的顺序返回结果呢?

回复内容:

想知道有没有一个方法能够让mysql按照指定的顺序返回数据。
例如我想搜索id=1、2、3的数据。
无论是写成where id in(1,2,3)还是where id in (1,3,2),mysql都是按照1、2、3的顺序返回结果,能不能指定mysql按照1、3、2的顺序返回结果呢?

SELECT id, name
FROM mytable
WHERE name IN ('B', 'A', 'D', 'E', 'C')
ORDER BY FIELD(name, 'B', 'A', 'D', 'E', 'C')

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!