Analyzing mysql table inside a comma delimited string contains a single string

Requirements: query user table roleid have user accounts 8

Table data for each user may have multiple roles, it may roleid string separated by commas and a plurality

Try a

SELECT account, roleid FROM sys_user WHERE roleid = '8'

Results: Only one user can check out the roles, contains two roles of users test the query does not come out

 Try two

SELECT account, roleid FROM sys_user WHERE roleid LIKE '%8%'

Results: 18 will contain user administrator role is also to query processing

Try three

Reference: https: //blog.csdn.net/Smile_Miracle/article/details/56008785

SELECT account, roleid FROM sys_user WHERE FIND_IN_SET('8',roleid)

 Results: exact match

Guess you like

Origin www.cnblogs.com/cailijuan/p/11724418.html