当前位置: 代码迷 >> ASP.NET >> where id in (.)的自动排序有关问题
  详细解决方案

where id in (.)的自动排序有关问题

热度:1977   发布时间:2013-02-25 00:00:00.0
where id in (...)的自动排序问题
Select   ProContent_name   From   ProContent   where   ProContent_ID   in   (9336,1137,8440)

这样搜索出来的数据   默认是按1137   8440   9336   来排序
如何是上面的语句按照输入的顺序来排   如:上面的语句的排序是9336,1137,8440
来排

我现在用的方法是截掉   按union   all   来链接,有其他方法吗?

------解决方案--------------------------------------------------------
不使用In,而改用Exists,或把条件拆成表然后使用关联查询。
------解决方案--------------------------------------------------------
Select ProContent_name From ProContent where ProContent_ID in =9336
union all
Select ProContent_name From ProContent where ProContent_ID in 1137
union all
Select ProContent_name From ProContent where ProContent_ID in =8440
------解决方案--------------------------------------------------------
WNASP的方法比in 要高效。

要排序,自己选择要排序的字段,再添加一个order by 子句就可以了
  相关解决方案