0

I have this Mysql Query:

SELECT page_id FROM page
WHERE page_title IN ('paul', 'mccartney')

My target is to get the article which includes this two words (in this example possible more words). I have a article where page_title contains 'paul mccartney'. The problem he's only searching for rows which containing on of the words, and it returns me the entry with only 'paul' as the page_title. I want, that the server returns the row where the page_title contains every of my words which are in the in clausle.

Name
  • 139
  • 2
  • 9
  • *"I have a article where page_title contains 'paul mccartney'"* and you're using `IN()`? that doesn't make any sense and your question is unclear. You need to show us what your db schema looks like. – Funk Forty Niner Jan 20 '16 at 18:58
  • it looks like this http://prntscr.com/9smpoe – Name Jan 20 '16 at 19:01
  • `IN()` is an array search of a column. You want `WHERE page_title = "paul mccartney"` – Jay Blanchard Jan 20 '16 at 19:03
  • yes it makes no sense and i don't know how i can solve the problem fast, because i know i can use the LIKE parameter for every word but it's very slow if there are mor than 3 words. – Name Jan 20 '16 at 19:03
  • 1
    how can it be slow? if your db's not indexed, then that will slow it down. MySQL should be able to handle thousands of records with no problem. Your query's failing because those contain underscores. another issue – Funk Forty Niner Jan 20 '16 at 19:04
  • did you know how i can find out if my db's are indexed? – Name Jan 20 '16 at 19:06
  • `LIKE '%mcartney%'` I can't see how that would be slow. But if your db's setup to be case-sensitive, that could be another issue. – Funk Forty Niner Jan 20 '16 at 19:06
  • how to see if indexed https://dev.mysql.com/doc/refman/5.0/en/show-index.html `SHOW INDEX FROM [tablename]` - http://stackoverflow.com/a/5213364/ – Funk Forty Niner Jan 20 '16 at 19:08
  • made a mistake, I missed a "c" `LIKE '%mccartney%'` but am sure you knew that ;-) – Funk Forty Niner Jan 20 '16 at 19:12
  • haha yes saw it. And i used the show index command and it returns me that http://prntscr.com/9smxa8 is it good? – Name Jan 20 '16 at 19:17
  • Do an EXPLAIN with the query to see which index is uses. – Jay Blanchard Jan 20 '16 at 19:25
  • what did u mean with explain? – Name Jan 20 '16 at 19:41

1 Answers1

1

You could always use union

SELECT page_id FROM page
WHERE page_title Like '%paul%'
UNION 
SELECT page_id FROM page
WHERE page_title Like '%mccartney%'
Fred
  • 5,663
  • 4
  • 45
  • 74