mysql where in order by field自定义排序

先看下mysql的默认排序

select id from article where id in(63261,63262,63269);

+-------+

|   id     |

+-------+

| 63261 |

| 63262 |

| 63269 |

+-------+

如果我想63262在第一个63261在最后一个怎么办?

select id from article where id in(63261,63262,63269) order by field(id,63262,63269,63261);

+-------+

|   id     |

+-------+

| 63262 |

| 63269 |

| 63261 |

+-------+


原文:http://blog.linuxphp.org/archives/1588/

你可能感兴趣的:(mysql where in order by field自定义排序)