0

Hi Im trying to make a keywords search for a java program I'm working on. I have run into a wall trying to work out how I can pass a string that contains 1-n words separated by spaces and then see if the column in the mysql database has any. If it contains at least one I want it to return the the selected data.

I have tried using the WHERE LIKE way of doing it but it doesnt seem to work

eg

SELECT `Data`
FROM `TABLE`
WHERE `Keywords` LIKE passedString
1

3 Answers 3

2

Use %, it represents zero, one, or multiple characters.

SELECT `Data`FROM `TABLE`WHERE `Keywords` LIKE '%passedString%'
Sign up to request clarification or add additional context in comments.

2 Comments

Will this split the passed string into characters? Or will they still be whole words?
I think so you got confused. It will return those rows which contains 'passedString' in 'Data' column.
0

Try

SELECT `Data` FROM `TABLE` WHERE `Keywords` LIKE + '%' + passedString + '%'

But before you have to split the passed String into single Strings (words) and run your query in a loop until you find your desired result.

Comments

0

The "%" sign is used to define wildcards (missing letters) both before and after the pattern.

SELECT Data
FROM TABLE
WHERE Keywords LIKE '%passedString%'

% A substitute for zero or more characters.

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.