6
I have this table below which has two columns, being id
and description
:
CREATE TABLE myBigTable (
id INT(11) AUTO_INCREMENT PRIMARY KEY,
description TEXT NOT NULL
)
After entering some records, I made a select simple and resulted in this below:
+----+-----------------------+
| id | description |
+----+-----------------------+
| 1 | joão de santo cristo |
| 2 | eduardo e mô nica |
| 3 | santo cristo joão |
| 4 | cristo tadeu joão |
| 5 | juazeiro do joão |
+----+-----------------------+
Would like a select that returns the amount of times each word appears in a given column, for example in the column description
. Below follows the return in which it would be desired, containing the word and the quantity. See:
+------------+----------+
| work | qnt |
+------------+----------+
| joão | 4 |
| cristo | 3 |
| santo | 2 |
| ... | ... |
+------------+----------+
I did a small test using LIKE, but I have to put the word in which I want to return
SELECT count(*) as qnt FROM `phrase` WHERE description LIKE "%joao%"
Return:
+----------+
| qnt |
+----------+
| 4 |
+----------+
How would a select to return the words that appear most in a given column? It is possible to do this using only database resources?
Note: it need not necessarily be the amount of times a word appears, but rather, if possible, the amount of lines it meets.
You’ve been listening a lot Urban Legion - 2 :P
– MarceloBoni
@Bonifazio! =)
– viana
I find a very complex question, I do not know if there is a performative way to do this :P first would have to explode every word of each line, and then count using LIKE "% string %" and excluding those that have already entered the count...
– MarceloBoni
It would be a mixture of this function with this logic
– MarceloBoni
You have a maximum length of words. For example thousand? Did not answer the question Xp
– Bruno Costa
@Brunocosta does not have the maximum size, but I would need at most 100, which would be enough to make decisions. And now, responded?!
– viana
the point of your test is if Voce has the same word in the same field ex.
joão de são joão del rey
, would have to count 2x right?– andrepaulo
with the same problem if solve brand solved in which
– Barack