在Mysql中使用in子句查询和排序

Question:

 I am stuck on mysql IN function using variable.can anybody provide me with source code for

       1. HTML form of multiple selection of combo box and
      2. extracting result for selected values using IN function

        e.g. category ID selected is 1,2,3,4,5,6, sql query would be
        $rsresult=mysql_query("select * from tablename where fieldname in ????????? ");

          but it doesnt work,     Please Help!

Answer:

               SELECT * FROM tablename WHERE  fieldname IN ('US','UK','GB','CN')

        SELECT foo FROM  tablename WHERE foo IN (1,2)

        but, using IN(2,7,3,5) is returnig results in order 2,7,3,5, How can i get

        result in 2,5,3,7 order ? 
              

        SELECT * FROM table WHERE id IN(2,7,3,5) ORDER BY FIELD(id,2,5,3,7);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值