I am using mysql db and and i have a table called INFO it has a column INFO_NUMBER and INFO_SUBJECT and it contains string as
+--------------+-------------------------+
| INFO_NUMBER | INFO_SUBJECT |
+--------------+-------------------------+
| A3L1 | updated |
| A3L2 | updated updated |
开发者_运维知识库| A3L3 | updated updated updated |
+--------------+-------------------------+
and now i want to fetch only those record whose INFO_SUBJECT contains maximum of updated string through like keyword and i don't know how many times updated string should be appended
this is becoz of searching and my requirement is same.my query is : SELECT INFO_NUMBER,INFO_SUBJECT FROM INFO WHERE INFO_SUBJECT LIKE "UP%"; but it returns all the records.
Thanks
I doubt if this can be done with a single query (even if possible, there might be performance implications). But this might help Mysql count number of regex match per field
Based on your data this will work:
SELECT * FROM INFO where length(INFO_SUBJECT) in (select max(length(INFO_SUBJECT)) from INFO);
More time updated word is in string more its length.
SELECT *
FROM INFO
WHERE INFO_SUBJECT LIKE 'up%'
AND length(INFO_SUBJECT) IN (SELECT MAX(length(INFO_SUBJECT)) FROM INFO);
Credit goes to Harry Joy. He has already has answered your question. Small string I added with your permission Harry.
精彩评论