To filter how several values in a field meet the criteria, how to query

Source: Internet
Author: User
How do I query for several values that match the criteria in a field?
Is this the query? SELECT * FROM table where cateid=2 or cateid=4 or cateid=8 there is no other way:

I now get a character cateid= "2,4,8," what is the easiest way to take out the values that meet the criteria, Cateid the value of the length is not fixed, it may be cateid= "2,4,8,23,44," may also be cateid= "2,"

Thank you........

------Solution--------------------
SELECT * FROM table where Cateid in (2,4,8)
------Solution--------------------
Query with in condition, but the last face of the condition (, comma) is removed
------Solution--------------------
SQL Code
  SELECT * FROM table where cate_id in (2,4,8)
------Solution--------------------
Or efficiency should be higher, it is easier to write in.
PHP Code
$a =explode (', ', ' 2,4,8,23,44, '); $w = Array (); foreach ($a as $s) {  if (intval ($s))    $w []= ' cate_id= '. Intval ($s);} if (count ($w))  echo "select * from table where". Implode (' or ', $w);
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.