Forum Moderators: open
For example, this can be the data:
1,"Andres","27,43,12"
2,"Roberto","23,14,58"
3,"Sebastian","6,23,18"
I need to make a SQL query which grabs all records where the fields CHILDS holds a number 23 in its data. In this case, it should print ID 2 and 3.
How can i achieve this?
Thanks,
andres
i am having trouble by writing the regular expression in there. any ideas?
Regex gives EVERYONE trouble. It is non-trivial to write them.
There's a good O'Reilly book, called "Mastering Regular Expressions [oreilly.com]," that I highly recommend.
This [zvon.org] is also a useful site.
Related threads:
[webmasterworld.com...]
[webmasterworld.com...]
[webmasterworld.com...]
SELECT *
FROM table
WHERE FIND_IN_SET( '23', childs )
//Showing rows 0 - 0 (1 total, Query took 0.0004 sec)
SELECT *
FROM table
WHERE childs REGEXP '[[:<:]]23[[:>:]]'
//Showing rows 0 - 0 (1 total, Query took 0.0004 sec)
As you can see, they also take the exact amount of execution time.
Andres
SELECT *
FROM table
WHERE FIND_IN_SET( '23', childs )
ORDER BY RAND()
LIMIT 3
(they have to be random records.. but only 3 of them).