あなたが本当にそれに興味があるなら、テキスト(非SQL)をword_listと呼ばれるテーブルに解析するべきだと思います。
create table phrases (word1 varchar, word2 varchar, word3 varchar, cnt int);
そしてコード:
$q = query("select comment from comments");
while ($row = array_read_line($q)){
$words = preg_split('/\s/', $row['comment']);
$previous1 = false;
$previous2 = false;
foreach($words as $word){
if($previous1 and $previous2){
.. here comes quoting, security, mysql-injection-safety, min length
query("update relations set cnt = cnt+1 "
. " where word1 = '$previous1', word2 = '$previous2', word3='$word'" )
if (rows_afected == 0){
query("insert into relations "
. " set cnt = 1, word1 = '$previous1', "
. " word2 = '$previous2', word3='$word'" )
}
}
previous1 = $previous2;
$previous2 = $word;
}
}
次に、count desc で並べ替えます。