因为是同张表可以使用union或者union all 来查询,缺点是查询语句比较长
SELECT * FROM jzb_area WHERE id = 10
UNION SELECT * FROM jzb_area WHERE id = 32
UNION SELECT * FROM jzb_area WHERE id = 22
UNION SELECT * FROM jzb_area WHERE id = 76
UNION SELECT * FROM jzb_area WHERE id = 13
UNION SELECT * FROM jzb_area WHERE id = 44
MySQL可以通过field()函数自定义排序, 格式:
# field(field,value1,value2,...), 如遇到null或者不在列表中的数据则返回0
# FIELD(id,10,32,22,76,13,44) 正序排列
# FIELD(id,44,13,76,22,32,10) DESC 倒序排列
SELECT * FROM table WHERE id IN(10,32,22,76,13,44) ORDER BY FIELD(id,10,32,22,76,13,44);
网友评论