I have a LONGTEXT column that I use to store paragraphs of text. Let’s say that within these paragraphs there is something like:
Text text text text
COUNT: 75 text text
text text text text
text text text text
Would it be possible to do a comparative query the small string “COUNT: 75” out of all that text?
My first thought was something like
SELECT * FROM `books`
WHERE `paragraphs` LIKE '%COUNT: >0%'
Is this even possible?
Your
SELECTwill only find rows where the text contains exaclty the bit between the wildcard characters: you can’t combine aLIKEwith comparative logic like that.What you can do, though, is to strip out the relevant sections of text using a regular expression and then analyse that.
Bear in mind, though, that combining
all at once will not provide the best performance! I would suggest the following:
something manageable (i.e. 50 characters or so) to work with,
inserting this subtext into a separate table
So your trigger would have something like:
which would get you the next 10 characters after
'count:', trimmed of whitespace. you could then further refine that by e.g.to get rows where a numerical value follows the COUNT bit.
You can then extract numerical values next to COUNT, saving them as numbers in a separate table, and then use a JOIN like this:
See here
http://dev.mysql.com/doc/refman/5.1/en/string-functions.html
for the functions at your disposal.