0

Here is my query:

SELECT * FROM events WHERE (audience like '%Internal%20Medicine%') and ('$date' < end_date) order by end_date

In the database the audience column looks like this "Internal Medicine, Neurology, Radiology".

I need the query to match the exact string in between the commas.

Stephen
  • 707
  • 3
  • 13
  • 33
  • How are you building that query? – Andy Lester Jan 24 '14 at 22:45
  • Have a look at [this question](http://stackoverflow.com/q/12613926/1438733), which does the same thing but with space delimiting. Basically you want to match `%,X`, `X,%`, `%,X,%` and `X`, where `X` is the search string. You could also do a regex search, but that's not as efficient. – Cat Jan 24 '14 at 22:45

1 Answers1

1

Here is a way to do this:

SELECT *
FROM events
WHERE find_in_set('Internal Medicine', replace(audience, ', ', ',')) > 0 and ('$date' < end_date)
order by end_dat;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • Awesome! I tried the find_in_set before and it didn't work, I guess I didn't realize the the spaces after the commas mattered. – Stephen Jan 24 '14 at 23:58