0

I want to select a record n times in which n is the number of times a string has occurred in a field.

Example:

mytable:

+--------+------------------------------------+
|   id   |                content             |
+--------+------------------------------------+
|   1    | This string contains two strings.  |
|   2    | This is a string.                  |
|   3    | This does not contain our keyword. |
+--------+------------------------------------+

Now I want the result of such a hypothetical query to be like the following result:

/* hypothetical: this won't yield the desired result obviously */
SELECT * FROM mytable WHERE content LIKE "%string%";

+--------+------------------------------------+
|   id   |                content             |
+--------+------------------------------------+
|   1    | This string contains two strings.  |
|   1    | This string contains two strings.  |
|   2    | This is a string.                  |
+--------+------------------------------------+

Is this even possible?

Thanks

Milad.Nozari
  • 2,243
  • 3
  • 26
  • 47
  • 1
    you unnecessarily putting extra load on the DB and connection. why don't you do this on the client side? – Karoly Horvath Oct 08 '14 at 15:52
  • 1
    You'd first need to [count the number of occurrences](http://stackoverflow.com/questions/748276/using-sql-to-determine-word-count-stats-of-a-text-field). Then you'll probably need a `cursor`. Perhaps you should do this kind of processing in the application that executes the query instead of in the query itself? – user247702 Oct 08 '14 at 15:53
  • Well, this is gonna be a temporary fix to a missing relation table. I'm not doiong this in php because I need a pagination(pager) mechanism to work – Milad.Nozari Oct 08 '14 at 15:53

0 Answers0