"在"mysql子句 [英] " where in " mysql clause

查看:143
本文介绍了"在"mysql子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了一个mysql查询,其中有"where id in("22,20,21") 但是当我得到结果时,它的类似数组按升序排列,即20,21,20

i used a mysql query where there is "where id in ("22,20,21") " but when i get the result its like array ordered in asecending order ie 20,21,20

但是我需要的顺序与我给该子句的顺序相同

but i need it in the same order as i gave the clause

推荐答案

i 认为,您应该可以像下面这样使用FIELD关键字:

i think you should be able to use the FIELD keyword like so:

SELECT * FROM table
WHERE id in (22,20,21)
ORDER BY FIELD(id,22,20,21);

这是特定于mysql的,看起来很神奇,但是可以.

this is mysql specific, and seems magical, but it works.

这篇关于"在"mysql子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆