3

I have a column with description and inside it can contain # value . what I want is all the words searched from that column with #tag

This is my query

SELECT description FROM  photo where description like '%#aw%';

and this is what I get as output

description
'nice place #awesome'
'my pc #awe'
' nice design #aw'
'my table #awesomedatabase'

and what I want is this output how to modify my query in order to get below output

 description 
 #awesome
 #awe
 #aw
 #awesomedatabase
3

You can use the INSTR function of MYSQL to find the starting position of the word matching your delimiter '%#aw%'. And then use sub string to fetch the word of your interest.

for eg. SELECT SUBSTR(description,INSTR (description,'#')) FROM photo where description like '%#aw%';

The problem here though is that if the word is followed by anything, it will also be a part of your output. You will need to find the position of the immediate next 'blank space' and use it as the LEN parameter (the 3rd param in SUBSTR function).

0

Try this

SELECT description FROM  photo where description like '#aw%';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.