sql to match number in string
I have a table that has a comma separated list of ids in one of the fields (not my doing). I want to know if I can use LIKE to match a number in this string? The problem is I don't want to get similar numbers. Is there a way to match a number with no numeric charcters on either side?
SELECT * FROM table WHERE activitiesids LIKE 6
   | ac开发者_如何转开发tivitiesids |
---+---------------+---
   |   3,16,8,6    |
---+---------------+---
   |       6       |
---+---------------+---
   |      7,560    |
---+---------------+---
Haven't tested but you can try something like this:
SELECT * FROM table WHERE activitiesids REGEXP '[[:<:]][0-9]+[[:>:]]';
Something like that:
WHERE ids LIKE '%,16,%' OR ids LIKE '%,16' OR ids LIKE '16,%';
Postgresql even has pattern matching - I don't know for mysql:
WHERE ids ~ '^(.*,)?16(,.*)?$'; 
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论