0

Tablename: tbl_person
Columns: id,name,bio

Sample Data: (id,name,bio)
1,Mike,Cambridge university degree in physics
2,Pete,Cambridge university degree in geology
3,Sam,Oxford university degree in geology

Problem: I would like to create a (My'SQL') search that can take multiple values and search and match them in one column

Example:
specifically search for: cambridge geology
I would like it to return record 2,Pete
and not all the record (because they contain matching keywords cambridge,geology)

The search that I have so far is
SELECT * FROM tbl_person WHERE tbl_person.bio IN ('cambridge','geology')
--Now this does not return a match--
Any Ideas please

1
  • Next time you can replace does not work at all with does not return any match ;-) Commented Jan 26, 2011 at 11:36

3 Answers 3

1
    SELECT * FROM tbl_person WHERE tbl_person.bio
    LIKE '%cambridge%' AND tbl_person.bio LIKE '%geology%'
Sign up to request clarification or add additional context in comments.

Comments

1

try fulltext searching which will give you more functionality and better performance

http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html

http://dev.mysql.com/doc/refman/5.0/en/fulltext-boolean.html

Any way to achieve fulltext-like search on InnoDB

Comments

0
SELECT
  *
FROM
  tbl_person
WHERE
  bio LIKE '%cambridge%'
AND
  bio LIKE '%geology%'

You will generate all the LIKE clauses for the WHERE clause in your program based on the search your user did, then AND them together to create the query.

1 Comment

Nice one, Just what Im looking for. I cannot understand the MySQL reference library all the time. Thanks alot

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.