code2b
code2b

Reputation: 113

search in a table

I have this website to search for books, there is only ONE text field, to search by words, title author, whatever it types.

if the name of the book is hello goodbye, and the author is A. Jones

if i type hello
i get the result of the book (my query is using the like statement)
i check if title like %string_introduced% or author like %string_introduced% using sql in java

the problem is when i introduce in the textfield "hello jones" it tells me there are no results

The problem is that this is translated to where title like %hello jones% or author like %hello jones%, this is why it doesn't work

Is there a way to do this in sql, without having to do a split of the string?

Upvotes: 0

Views: 137

Answers (1)

Mark Byers
Mark Byers

Reputation: 838096

No, I think you will have to split the string.

WHERE (title LIKE '%hello%' OR title LIKE '%jones%')
OR    (author LIKE '%hello%' OR author LIKE '%jones%')

The parentheses aren't necessary here. They are just for clarity.

Related:

Upvotes: 2

Related Questions