4

The question may be asked several times and I checked all of them but I can't get the answer. I have a field named variables in my database 'test'.I have worked the query

select 'variables' from test WHERE variables LIKE '%{$ifIndex}%';

variables field contains comma seperated strings like ifIndex, IfType, IfStatus but I can't get it!

3 Answers 3

5

This will achieve the results you want when you put the string you are looking for using just the % for the wildcard on either side.

select variables from test WHERE variables LIKE '%ifIndex%';
Sign up to request clarification or add additional context in comments.

Comments

3

Try the following:

select variables from test WHERE 'ifIndex' LIKE CONCAT('%',`variables` , '%') ;

if you're trying to match just the start:

select variables from test WHERE 'ifIndex' LIKE CONCAT(`variables` , '%') 

3 Comments

What about if the field contains space. can i replace it when querying?
what do you mean by field? like the field name? or the value in the field being searched? If its the field name, you should dhave no problem. Otherwise, you need to take into account regular expressions.. see dev.mysql.com/doc/refman/5.0/en/…
i mean sometimes the 'variable' in the table contains ' ifIndex'
3

Try the following code

select variables from test
WHERE variables LIKE '%{$ifIndex}%';

For field names don't put the single quotaition.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.