MYSQL match against query two tables

2019-09-14 17:05发布

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条回答
该账号已被封号
2楼-- · 2019-09-14 18:01

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

查看更多
登录 后发表回答