Mysql FIND_IN_SET () Usage

Source: Internet
Author: User

Mysql's FIND_IN_SET () usage FIND_IN_SET (str, strlist) returns the serial number of str in the strlist of the string set (if any parameter is NULL, NULL is returned. If str is not found, 0 is returned, an exception occurs when parameter 1 contains ",".) Example: query the table field pingid = (, 3,) SELECT * FROM 'linkinfo 'WHERE 'pingid' REGEXP' {id }, 'AND 'pingid' not regexp' [[: alnum:] + {id}, 'Use the preceding statement to query AND use FIND_IN_SET () simpler SELECT * FROMlinkinfoWHEREFIND_IN_SET ('1', pingid) originally thought mysql could perform such queries: select id, list, name from table where 'daodao 'IN (list); (1) note: 1. table contains three fields: int, list: varchar (255), name: varchar (255). In this way, only when name is the first element in the list, the query is valid. Otherwise, no results will be returned. Even if 'daocao' is actually IN the list, let's take a look at this: select id, list, name from table where 'daocao' IN ('libk ', 'zyfon', 'daodao '); (2) can it be ------------------------------------------------------------- what is the difference between the two? Why can't the first one get the correct result, but the second one get the result. The reason is that (1) in (list) list is a variable, and (2) in ('libk', 'zyfon', 'daodao ') is a constant, so if you want (1) to work correctly, use find_in_set (): select id, list, name from table where FIND_IN_SET ('daodao ', list); (1). Conclusion: If list is a constant, you can use IN directly; otherwise, use the FIND_IN_SET () function.

Related Article

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.