MYSQL match against query two tables

空扰寡人 提交于 2019-12-13 03:37:13

问题


Is it possible to do a match against a query with two tables using a join? The tricky part might be the index on the table but maybe there is a way.. sql is not my strong suit. Many thanks. I imagine it might be something like the following:

SELECT * FROM 'pages' p
LEFT JOIN `tags` t
ON p.id = u.pageid
WHERE MATCH(p.shdescript,t.tag) AGAINST ('romance, relationship')

Many thanks


回答1:


It's possible, but you need to have text indexes.

mysql> alter table pages add fulltext index_text(shdescript);

mysql> alter table tags add fulltext index_text(tag);

SELECT * FROM 'pages' p
LEFT JOIN `tags` t
ON p.id = u.pageid
WHERE MATCH(p.shdescript,t.tag) AGAINST ('romance relationship')

I guess that's enough to work.

EDIT:

As of MySQL 5.6 the above fulltext search can be done on the MyISAM & InnoDB storage engines. On earlier MySQL versions only MyISAM tables supported fulltext indexes.

http://dev.mysql.com/doc/refman/5.6/en/fulltext-search.html



来源:https://stackoverflow.com/questions/10823202/mysql-match-against-query-two-tables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!